Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-在动画运行时禁用函数_Jquery_Function_Scroll - Fatal编程技术网

jQuery-在动画运行时禁用函数

jQuery-在动画运行时禁用函数,jquery,function,scroll,Jquery,Function,Scroll,我正在使用下面的代码在滚动到一个粘性导航条上添加类。它工作正常,但我希望它在单击导航栏中的和li元素时禁用滚动功能,这样当用户单击导航后滚动动画启动时,它不会开始更改类,所以我想我需要禁用滚动功能,直到滚动动画完成。有什么建议吗 编辑 也许我不清楚。 当用户单击li项目时,我使用滚动动画。我还使用了一个函数,如果用户滚动到li项所对应的div之前,该函数将添加活动类。当用户现在位于页面顶部并单击其中一个li项时,活动类将首先添加到他们单击的li项,然后添加到所有li项,但我希望它仅保留在他们单击

我正在使用下面的代码在滚动到一个粘性导航条上添加类。它工作正常,但我希望它在单击导航栏中的和li元素时禁用滚动功能,这样当用户单击导航后滚动动画启动时,它不会开始更改类,所以我想我需要禁用滚动功能,直到滚动动画完成。有什么建议吗

编辑 也许我不清楚。 当用户单击li项目时,我使用滚动动画。我还使用了一个函数,如果用户滚动到li项所对应的div之前,该函数将添加活动类。当用户现在位于页面顶部并单击其中一个li项时,活动类将首先添加到他们单击的li项,然后添加到所有li项,但我希望它仅保留在他们单击的li项上,因此可能需要禁用添加活动类滚动功能,直到从点击完成了吗

$(window).scroll(function(){
    var top = $(window).scrollTop(),
    nav_distance = 450,
    grid_3_distance = $("section.grid.third").offset().top - 1,
    grid_4_distance = $("section.grid.fourth").offset().top - 230;

    if(top > nav_distance) {
        $("section.grid.second ul").addClass("fixed");
    } else if(top < nav_distance) {
        $("section.grid.second ul").removeClass("fixed");
    }

    if(top > nav_distance){
        $("section.grid.second ul nav li").removeClass("active");
        $("section.grid.second ul nav li[data-intern='.grid.second']").addClass("active");
    }

    if(top > grid_3_distance){
        $("section.grid.second ul nav li").removeClass("active");
        $("section.grid.second ul nav li[data-intern='.grid.third']").addClass("active");
    }

    if(top > grid_4_distance){
        $("section.grid.second ul nav li").removeClass("active");
        $("section.grid.second ul nav li[data-intern='.grid.fourth']").addClass("active");
    }
});

$(function(){
    $("section.grid.second ul nav li").click(function(){
        $("section.grid.second ul nav li").removeClass("active");
        $(this).addClass("active");
        var id = $(this).attr("data-intern");
        $('html,body').animate({scrollTop:$(id).offset().top}, 500);
    });
$(窗口)。滚动(函数(){
var top=$(窗口).scrollTop(),
导航距离=450,
grid_3_distance=$(“section.grid.third”).offset().top-1,
grid_4_distance=$(“section.grid.fourth”).offset().top-230;
如果(顶部>导航距离){
$(“section.grid.second ul”).addClass(“固定”);
}否则如果(顶部<导航距离){
$(“section.grid.second ul”).removeClass(“固定”);
}
如果(顶部>导航距离){
$(“section.grid.second ul nav li”).removeClass(“active”);
$(“section.grid.second ul nav li[数据内部='.grid.second'])).addClass(“活动”);
}
如果(顶部>栅格3距离){
$(“section.grid.second ul nav li”).removeClass(“active”);
$(“section.grid.second ul nav li[数据内部='.grid.third'])).addClass(“活动”);
}
如果(顶部>栅格4距离){
$(“section.grid.second ul nav li”).removeClass(“active”);
$(“section.grid.second ul nav li[数据内部='.grid.fourth'])).addClass(“活动”);
}
});
$(函数(){
$(“section.grid.second ul nav li”)。单击(函数(){
$(“section.grid.second ul nav li”).removeClass(“active”);
$(此).addClass(“活动”);
var id=$(this.attr(“数据实习生”);
$('html,body').animate({scrollTop:$(id).offset().top},500);
});

我建议你继续做你所描述的。你的问题中不清楚你在哪一部分有困难。我编辑了这个问题以使自己更清楚。我希望你能更好地理解我现在要做的事情。jQuery有一个可能对你有帮助的方法。你能把你的问题复制到JSFIDLE中吗?