可滚动 div:如何从可滚动 div 的 OnScroll 事件检测滚动方向?
如何从 OnScroll 事件检测可滚动 div 的滚动方向?如果用户向上滚动,我想向scrollTop 添加 15;如果用户向下滚动,我想向scrollTop 添加 15。不使用JQuery 可以吗?
How to detect the scroll direction for a scrollable div , From OnScroll event? I want to add 15 to scrollTop, if user scrolls up and subtract 15, if user scrolls down. Is it possible with out using JQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JSFIDDLE
根据需要使用它。
JSFIDDLE
Use it as you want.
我能想到的最简单的方法如下。如果您可以将
let oldScroll
包装到一个闭包中以使其更清晰,那就太好了,但这不是必需的。The simplest way I can think of is the following. It would be nice if you could wrap
let oldScroll
into a closure to make it cleaner, but it's not necessary.