如何在jQuery中检测水平滚动?

Aha*_*lem 36 jquery scroll

如何使用jQuery检测水平滚动?

这将获得所有卷轴:

$(window).scroll(function () {
    alert('in');
});
Run Code Online (Sandbox Code Playgroud)

我只想要横向的.

ale*_*lex 41

这似乎有效.

var lastScrollLeft = 0;
$(window).scroll(function() {
    var documentScrollLeft = $(document).scrollLeft();
    if (lastScrollLeft != documentScrollLeft) {
        console.log('scroll x');
        lastScrollLeft = documentScrollLeft;
    }
});
Run Code Online (Sandbox Code Playgroud)

jsFiddle.


dun*_*ood 6

基于以上代码在水平滚动中显示左或右方向的更新:

var lastPos = 0;
$(window).scroll(function() {
    var currPos = $(document).scrollLeft();

    if (lastPos < currPos) {
        console.log('scroll right');
    } 
    if (lastPos > currPos) 
    {
        console.log('scroll left');
    }

    lastPos = currPos;
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/EsPk7/7/进行测试