Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
Javascript 使用鼠标滚轮滚动节_Javascript_Jquery_Mousewheel - Fatal编程技术网

Javascript 使用鼠标滚轮滚动节

Javascript 使用鼠标滚轮滚动节,javascript,jquery,mousewheel,Javascript,Jquery,Mousewheel,我正在使用鼠标滚轮插件来滚动页面的各个部分 在动画完全完成之前,我应该如何禁用我编写的函数 我正在运行stop(),但这只会抵消动画 $('section').mousewheel(function(event, delta, deltaX, deltaY) { $('section' ).waypoint(function(direction){ thisID = $(this); },{ offset: '25%' }); if (delta > 0) { con

我正在使用鼠标滚轮插件来滚动页面的各个部分

在动画完全完成之前,我应该如何禁用我编写的函数

我正在运行stop(),但这只会抵消动画

$('section').mousewheel(function(event, delta, deltaX, deltaY) {

$('section' ).waypoint(function(direction){
    thisID = $(this); 
},{ offset: '25%' });

if (delta > 0) {
    console.log('up');
    if ($(this).not(":first-child")) { 
        //$(this).animate(function(){
        $('html, body').stop().animate({
            scrollTop: thisID.prev().offset().top
        }, 1000);
            //});
    }else {
        $('html, body').stop().animate({
            scrollTop: thisID.offset().top
        }, 1000);
    }
    }
else if (delta < 0) {

    if ($(this).not(":first-child")) { 
        $('html, body').stop().animate({
            scrollTop: thisID.next().offset().top
        }, 1000);
    }
    else {
        $('html, body').stop().animate({
            scrollTop: thisID.offset().top
        }, 1000);
    }

    console.log('down');
}
return false; // prevent default
});
$('section')。鼠标滚轮(函数(事件、增量、增量、增量){
$('section')。航路点(功能(方向){
thisID=$(this);
},{偏移量:25%});
如果(增量>0){
console.log('up');
if($(this.not(“:first child”){
//$(this.animate(function()){
$('html,body').stop().animate({
scrollTop:thisID.prev().offset().top
}, 1000);
//});
}否则{
$('html,body').stop().animate({
scrollTop:thisID.offset().top
}, 1000);
}
}
else if(delta<0){
if($(this.not(“:first child”){
$('html,body').stop().animate({
scrollTop:thisID.next().offset().top
}, 1000);
}
否则{
$('html,body').stop().animate({
scrollTop:thisID.offset().top
}, 1000);
}
console.log('down');
}
返回false;//防止默认值
});

一种方法是创建一个“stoplight”变量。在函数开始时将其设置为
False
,然后在动画结束时使用函数的
complete
参数将其重新设置为
True
。然后,仅当此变量为
True

时,才运行主函数,而不是重新设计轮子。您可能需要查看以下内容:


当你开始处理触摸设备、触摸屏、旧浏览器、轨迹板或苹果笔记本电脑中的动态滚动时,它将使你免于许多头疼的事情

谢谢你,我能用你的推荐使它工作。@hyperdrive很乐意帮忙!