【发布时间】:2011-07-20 22:55:31
【问题描述】:
目前,我将此脚本用于一种“标签”系统。单击一个选项卡时,它会隐藏所有其他选项卡。他们都是div的。但是现在,我认为在选定的 div 加载之前它的衰减速度还不够快。它最终在被选中并正在显示的 div 下方移动。
我不想切换,因为如您所见,我有 5 个选项卡,我想在单击它们时打开它们各自的“_s”div。淡出,淡入。
有什么方法可以让淡出在淡入之前发生,或者添加延迟?我不知道如何在这个脚本中添加延迟,或者在新的 div 淡入之前检查以确保 div 完全淡化。
如果有任何帮助,我将不胜感激。谢谢!
<script>
$("#teach_one").click(function() {
$("#teach_one_s").fadeIn("slow");
$("#teach_two_s").fadeOut("fast");
$("#teach_three_s").fadeOut("fast");
$("#teach_four_s").fadeOut("fast");
$("#teach_five_s").fadeOut("fast");
});
$("#teach_two").click(function () {
$("#teach_two_s").fadeIn("slow");
$("#teach_one_s").fadeOut("fast");
$("#teach_three_s").fadeOut("fast");
$("#teach_four_s").fadeOut("fast");
$("#teach_five_s").fadeOut("fast");
});
$("#teach_three").click(function () {
$("#teach_three_s").fadeIn("slow");
$("#teach_one_s").fadeOut("fast");
$("#teach_two_s").fadeOut("fast");
$("#teach_four_s").fadeOut("fast");
$("#teach_five_s").fadeOut("fast");
});
$("#teach_four").click(function () {
$("#teach_four_s").fadeIn("slow");
$("#teach_one_s").fadeOut("fast");
$("#teach_two_s").fadeOut("fast");
$("#teach_three_s").fadeOut("fast");
$("#teach_five_s").fadeOut("fast");
});
$("#teach_five").click(function () {
$("#teach_five_s").fadeIn("slow");
$("#teach_one_s").fadeOut("fast");
$("#teach_two_s").fadeOut("fast");
$("#teach_three_s").fadeOut("fast");
$("#teach_four_s").fadeOut("fast");
});
</script>
根据您的要求,这是我的 HTML:
<ul class="noselect teach_home_navigator_tabs">
<li id="teach_one">
</li>
<li id="teach_two">
</li>
<li id="teach_three">
</li>
<li id="teach_four">
</li>
<li id="teach_five">
</li>
</ul>
<div class="infotab teach_round" id="teach_one_s">
stufff
</div>
<div class="infotab teach_round" id="teach_two_s">
stufff
</div>
<div class="infotab teach_round" id="teach_three_s">
stufff
</div>
<div class="infotab teach_round" id="teach_four_s">
stufff
</div>
<div class="infotab teach_round" id="teach_five_s">
stufff
</div>
【问题讨论】:
-
如果您发布您的标记或代表性示例,我们可能会简化您的 jQuery。很多,我想。
-
如果你展示你的 HTML,这会更容易。
-
它不会让我添加 HTML。它说我发布了太多链接。
-
查看我与您的标记相关的答案:stackoverflow.com/questions/5399632/…
标签: jquery performance delay fadein fadeout