Get horizontal scroll event in js

后端 未结 3 1850
春和景丽
春和景丽 2020-12-31 05:10

What I want to do, is to catch the event when the user is scrolling div horizontally. For vertical scroll I am using event \'mousewheel\' and it\'s working properly. ( horiz

3条回答
  •  轮回少年
    2020-12-31 06:06

    You can handle horizontal scrolling by :

    $("#someContainer").on("scroll", function (e) {
                horizontal = e.currentTarget.scrollLeft;
                vertical = e.currentTarget.scrollTop;
                });
    

    In this case this bind all kind of scroll events on this element so you can also handle

    Vertical by e.currentTarget.scrollTop

    and

    Horizontal by e.currentTarget.scrollLeft

提交回复
热议问题