Depending on which version of HTML you're using, you could use the onwheel
event, instead.
The onscroll
event works only if all the following are true:
- The div has
overflow: auto
, overflow: scroll
, overflow-y: scroll
, etc.
- The div currently has a visible scrollbar that can scroll.
- The mouse movement actually causes the scrollbar to scroll.
So the onscroll
event is not really suited for detecting general mouse wheel movement.
Please note that the onwheel
event is new in HTML 5. According to w3schools, it is pretty widely supported, though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…