What's the difference between “onwheel” and “onscroll” events?

前端 未结 4 2019
不知归路
不知归路 2020-12-20 13:09

When I tried to change the default scroll bar property, I found that it\'s not convenient by rewriting callback function for scroll() or onscroll e

相关标签:
4条回答
  • 2020-12-20 13:47

    MDN about onwheel:

    Non-standard
    This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

    The onwheel event gets fired when the mouse wheel is scrolled. This physical action may or may not also result in scroll events.

    Basically, onscroll is what you need.

    0 讨论(0)
  • 2020-12-20 13:57

    onwheel: Occurs when the mouse wheel is rolled up or down over an element.

    onscroll Occurs when an element's scrollbar is being scrolled.

    It's important to note that in Internet Explorer, the wheel event is only supported through addEventListener. You can't use the onwheel event attribute.

    onwheel doesn't work in Safari or in IE8 or earlier.

    0 讨论(0)
  • 2020-12-20 13:57

    The onwheel event triggers on scroll AND on zoom, as you move the mouse wheel, while the onscroll event only occurs when an element's scrollbar is being scrolled (i believe that includes touch scrolling as well).

    0 讨论(0)
  • 2020-12-20 14:01

    onwheel specifically fires when the mouse wheel is spun. onscroll fires for any kind of scrolling, including keyboard buttons like the arrow keys, Home, End, Page Up, Page Down, space bar, tabbing etc.

    Note that onwheel is non-standard and should be avoided unless you're specifically targeting browsers that support it and/or are providing an extra feature whose absence won't be felt.

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