Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 如何在jquery中通过dom引擎检测页面滚动_Javascript_Jquery_Scroll - Fatal编程技术网

Javascript 如何在jquery中通过dom引擎检测页面滚动

Javascript 如何在jquery中通过dom引擎检测页面滚动,javascript,jquery,scroll,Javascript,Jquery,Scroll,使用jQuery的滚动功能,您可以检测任何滚动事件,无论它是由用户创建的,即鼠标滚动、拖动滚动条或DOM引擎添加或删除元素。如何区分DOM引擎触发的滚动事件 清楚地表明了我的意思。有很多方法可以处理这个问题,但我不知道有哪种方法是非常正式的 一种简单的方法是,当您以编程方式启动滚动时,只需设置一个切换,例如设置一个类并在完成后将其删除。我必须证明这是怎么回事 $("#scrollable") .addClass('programatically-scrolling') .scro

使用jQuery的滚动功能,您可以检测任何滚动事件,无论它是由用户创建的,即鼠标滚动、拖动滚动条或DOM引擎添加或删除元素。如何区分DOM引擎触发的滚动事件


清楚地表明了我的意思。

有很多方法可以处理这个问题,但我不知道有哪种方法是非常正式的

一种简单的方法是,当您以编程方式启动滚动时,只需设置一个切换,例如设置一个类并在完成后将其删除。我必须证明这是怎么回事

$("#scrollable")
    .addClass('programatically-scrolling')
    .scrollTo({
        top: $("#scrollable").prop("scrollHeight") - $("#scrollable").innerHeight(),
        left: 0
    }, 1000, {
        axis: 'y',

        // Add a function to remove the toggle when the animation is complete
        onAfter: function () {
            $(this).removeClass('programatically-scrolling');
        }
    });

$("#scrollable").scroll(function (event) {

    // This will be true when your $.scrollTo animation is going
    // and false when you trigger the scroll with your mouse
    console.log($(this).hasClass('programatically-scrolling'));
});

还有其他方法可以解决这个问题,还有其他人也有。制作一个游戏可能是最有趣的,但我列出的解决方案可能是最简单的。

谢谢你的介绍。我想我会使用jquery鼠标滚轮插件,比如现在看来最简单的解决方案。因此,我将确保用户是否会使用鼠标滚轮滚动。目前,我不关心滚动拖动事件。