fade 函数 jquery 滑块被钩住了

fade function jquery slider is hooked

提问人:Yoeri Achterbergen 提问时间:9/8/2015 更新时间:9/8/2015 访问量:30

问:

我创建的代码可以工作,但是如果您快速单击 de 按钮,滑块就会被钩住。

J查询

$(document).ready(function(){
$(".list div").each(function(e) {
    if (e != 0)
        $(this).hide();
});

$("#next").click(function(){
    if ($(".list div:visible").next().length != 0){
        $(".list div:visible").stop().next().stop().fadeIn().prev().stop().fadeOut();

    } else {
        $(".list div:visible").fadeOut();
        $(".list div:first").fadeIn();
    }
    return false;
});

$("#prev").click(function(){
    if ($(".list div:visible").prev().length != 0){
        $(".list div:visible").prev().stop().fadeIn().next().stop().fadeOut();
    } else {
        $(".list div:visible").fadeOut();
        $(".list div:last").fadeIn();
    }
    return false;
});
});

这段代码有什么问题?

希望有人能帮助我。

问候 Yoeri

jQuery 按钮 滑块

评论

1赞 D4V1D 9/8/2015
仅触发动画。if(!$(elem).is(':animated')) {}
0赞 D4V1D 9/8/2015
如何用jQuery找出元素是否正在动画处理的可能重复?

答:

0赞 D4V1D 9/8/2015 #1

检查您的元素当前是否正在制作动画:

$("#next").click(function(){
    if ($(".list div:visible").next().length != 0 && !$(".list div:visible").is(':animated')){ // notice the second condition
        $(".list div:visible").stop().next().stop().fadeIn().prev().stop().fadeOut();

    } else {
        $(".list div:visible").fadeOut();
        $(".list div:first").fadeIn();
    }
    return false;
});

并做同样的事情$("#prev").click();