Get horizontal scroll event in js

后端 未结 3 1848
春和景丽
春和景丽 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 05:56

    e.currentTarget.scrollX instead of e.currentTarget.scrollLeft and e.currentTarget.scrollY instead of e.currentTarget.scrollTop

    0 讨论(0)
  • 2020-12-31 06:05

    I don't have the proper setup to test this, but $.scroll() should do the trick. It's probably preferable to binding the mousewheel event as well. People use all means of scrolling ;)

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题