问题描述
当我尝试更改默认滚动条属性时,我发现通过重写 scroll()
或 onscroll 事件,相反,我应该为onwheel事件重写一个回调函数。
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
events, instead, I should rewrite a callback function for "onwheel" events.
那么 onwheel 和
onscroll
无论如何?我想,浏览器默认的 onwheel
处理程序会自动触发 onscroll
函数来移动滚动条,这就是为什么 preventDefault
在 onwheel
的回调将阻止滚动条移动。我对吗?谁有更好更具体的解释?
So what's the difference between onwheel
and onscroll
anyways? I imagine that default onwheel
handler by browsers would automatically trigger onscroll
function to move the scroll bar, which is why preventDefault
in onwheel
's callback will prevent scroll bar moving. Am I right? Who has a better and more specific explanation?
推荐答案
onwheel
具体会触发。 onscroll
触发任何类型的滚动,包括键盘按钮,如箭头键,Home,End,Page Up,Page Down,空格键,标签等。
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.
请注意 onwheel
是非标准的,应该避免,除非您专门针对支持它的浏览器和/或提供额外功能,不会感觉不到。
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.
这篇关于“onwheel”和“onwheel”之间的区别是什么?和“onscroll”事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!