How to detect horizontal scrolling in jQuery?

前端 未结 4 474
时光说笑
时光说笑 2020-12-01 07:53

How do I detect horizontal scrolling with jQuery?

This will get all scrolls:

$(window).scroll(function () {
    alert(\'in\');
});

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 08:04

    This seems to work.

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

    jsFiddle.

提交回复
热议问题