JQuery OnClick 动画和 if 语句
过去 90 分钟左右我一直在试图解决这个问题。我有一个使用 JQuery 制作动画的网站,以及动画末尾出现的 2 个链接。当您单击任一链接时,div 会淡入以显示更多链接。到目前为止,一切正常(作为参考,链接 1 是“然后”,链接 2 是“现在”)。
我想要发生的情况是,假设用户单击“然后”。现在他想点击“现在”。我希望“Then”div 淡出,“Now”div 淡入。反之亦然。我觉得我的代码已经差不多了,但我是个 JS 菜鸟,似乎无法理解它。我也不想破坏我已经试图弄清楚的事情。代码如下:
//then + now animation
var thennav = document.getElementById('#thennavbox');
var nownav = document.getElementById('#nownavbox');
$(document).ready(function(){
$('#then').click(function(){
$('#thennavbox').fadeIn(1000);
});
$('#now').click(function(){
$('#nownavbox').fadeIn(1000);
});
});//end onclick animation
if(thennav.style.display=='none'){
$('#nownavbox').fadeOut(1000, function(){
$('#thennavbox').fadeIn(1000);
});
};
if(nownav.style.display=='none'){
$('#thennavbox').fadeOut(1000, function(){
$('#nownavbox').fadeIn(1000);
});
};//end if statements
//end then + now animation
就像我说的,一切都会按预期淡入。我只是无法让一个淡出而另一个淡入。我想也许我的 if 语句放错了地方。
I've been spending the last 90 minutes or so trying to figure this out. I've got a site animated with JQuery, and 2 links that appear at the end of the animation. When you click on either link, a div fades in to reveal more links. Everything is working up to this point (for reference, link 1 is "Then" and link 2 is "Now").
What I want to happen is let's say a user clicked on "Then". Now he wants to click "Now". I want the "Then" div to fade out and the "Now" div to fade in. And vice versa. I feel like my code is almost there, but I'm a total JS noob and can't seem to get it. I also don't want to bust up what I've already got trying to figure it out. Code follows:
//then + now animation
var thennav = document.getElementById('#thennavbox');
var nownav = document.getElementById('#nownavbox');
$(document).ready(function(){
$('#then').click(function(){
$('#thennavbox').fadeIn(1000);
});
$('#now').click(function(){
$('#nownavbox').fadeIn(1000);
});
});//end onclick animation
if(thennav.style.display=='none'){
$('#nownavbox').fadeOut(1000, function(){
$('#thennavbox').fadeIn(1000);
});
};
if(nownav.style.display=='none'){
$('#thennavbox').fadeOut(1000, function(){
$('#nownavbox').fadeIn(1000);
});
};//end if statements
//end then + now animation
Like I said, everything fades in as it's supposed to. I just can't get one to fade out and the other to fade in. I think perhaps my if statements are in the wrong place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)