jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何让这个jQuery比我的更快?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,我正在使用此脚本作为一种“选项卡”系统.单击一个选项卡时,它会隐藏所有其他选项卡.他们都是div.但是现在,我认为在选定的div加载之前它的消失速度不够快.它最终会被选中并正在显示的div下方移动.

我不想要切换,因为正如你所看到的,我有5个标签,我想在点击它们时打开它们各自的“_s”div.淡出,淡入.

任何使淡出效果在淡入之前发生的@L_944_5@,或者可能会延迟添加?我不知道如何在此脚本中添加延迟,或检查以确保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,并减少你的重复,你可以尝试使用这样的东西:

$('div[id^="teach_"]').click(
    function(){
        var showThis = this.id + '_s';
        $('#' + showThis).fadeOut('slow',function(){
                $('div[id$="_s"]').not($(this)).fadeIn('fast');
            });
    });

编辑以回应@Josh提供的html.

$('.each_home_navigator_tabs li').click(
    function(){
        var showThis = this.id + '_s';
        $('.infotab:visible').fadeOut('slow',function(){
                $('#' + showThis).fadeIn('fast');
            });
    });

文献:

> attribute-starts-with selector: ^=.
> attribute-ends-with selector: $=.
> not().

大佬总结

以上是大佬教程为你收集整理的如何让这个jQuery比我的更快?全部内容,希望文章能够帮你解决如何让这个jQuery比我的更快?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。