我有3个btns,它们是无序列表中的简单锚点标记,每个btns都有相应的t1,t2和t3。我也有3个类似的隐藏在CSS中的btns,它们分别具有t1-discover,t2-discover和t3-discover的ID。我想要实现的是,例如t1在5秒钟后被点击,然后在t1-discover和fadesOut t2-discover和t3discover中发现,对于t2相同& t3。这是我尝试使用jQuery:jQuery淡入淡出/延迟菜单
$("#t1").click(function() {
$("#t2-discover").stop().fadeOut(10);
$("#t3-discover").stop().fadeOut(10);
// delay fadein of link
setTimeout(function() {
$('#t1-discover').fadeIn(2000);
}, 5000);
});
$("#t2").click(function() {
$("#t1-discover").stop().fadeOut(10);
$("#t3-discover").stop().fadeOut(10);
// delay fadein of link
setTimeout(function() {
$('#t2-discover').fadeIn(2000);
}, 5000);
});
$("#t3").click(function() {
$("#t1-discover").stop().fadeOut(10);
$("#t2-discover").stop().fadeOut(10);
// delay fadein of link
setTimeout(function() {
$('#t3-discover').fadeIn(2000);
}, 5000);
});
这有点儿工作,延迟和衰落是有,但是当点击一个BTN不抵消其他2个动画他们淡入,但呆在那里有什么办法说淡入,但也取消并重置其他2个动画?我也想学会更高效地做到这一点,我确信这段代码非常精彩,但我仍然在学习!希望这是有道理的,并提前感谢。
@加比哇有点让我困惑,但很好的解决方案。我理解它的大部分。 $ thisid是另一个变量或内置到jQuery中的东西?这个标准最终是我想用jquery编写的,但可能需要一些时间! @尼克得把它作为一个更加优雅的解决方案。 – mtwallet 2010-01-31 13:31:46
'@ thisid'只是一个普通的变量(与jquery无关)..你可以把任何东西放在那里..还在变量前面加了'var'关键字,因为我忘记了它。 – 2010-01-31 16:55:44
很高兴它工作正常:)代码重用和DRY方法是非常好的做法。 – 2010-01-31 16:57:57