如何检测滚动条上的鼠标按下? (或“scrollEnd”事件)
有人知道如何检测滚动条上的 mouseup 事件吗?它在 FF 中有效,但在 Chrome 或 IE9 中无效。
我设置了一个快速演示: http://jsfiddle.net/2EE3P/
总体想法是,我想要检测 scrollEnd
事件。显然没有这样的事情,所以我打算结合使用 mouseUp
和计时器,但是 mouseUp
在大多数浏览器中都不会触发! div 包含一个项目网格,因此当用户停止滚动时,我想将滚动位置调整到有意义的最近点,例如最近单元格的边缘。但是,如果它们处于滚动中间,我不想自动调整位置。
我也很乐意接受任何给我相当于 scrollEnd
的答案
Anyone have any idea how to detect a mouseup event on a scrollbar? It works in FF, but not in Chrome or IE9.
I set up a quick demo: http://jsfiddle.net/2EE3P/
The overall idea is that I want to detect a scrollEnd
event. There is obviously no such thing so I was going with a combination of mouseUp
and timers, but mouseUp
isn't firing in most browsers! The div contains a grid of items so when the user stops scrolling I want to adjust the scroll position to the nearest point that makes sense, e.g. the edge of the nearest cell. I don't, however, want to automatically adjust the position if they're in the middle of scrolling.
I'll also happily accept any answer that gives me the equivalent of scrollEnd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
找到了一种无需计时器即可工作的解决方案,但仅当您滚动整个窗口时才有效。
很脏..但是有效。
found a solution that works without timers but only if you are scrolling the complete window.
pretty dirty .. but works.
使用 jquery 有一个 .scroll 事件可以使用。也许使用全局变量来跟踪 .scrollTop() (它返回屏幕上方的像素数)何时停止变化?仍然会产生竞争条件,但它应该有效。
Using jquery there is a .scroll event you can use. Maybe use a global variable to keep track of when .scrollTop() (it returns the number of pixels there are above the screen) has stopped changing? Still creates a race condition, but it should work.
回答我自己的问题,这样我就可以关闭它——对此没有好的解决方案,所以计时器......
Answering my own question so I can close it -- there is no good solution to this, so timers it is...
我正在处理同样的问题。对我来说 IE9 不会为滚动条发出 mouseup 事件。所以,我检查了一下,在 IE9 上,当你“mouseup”时,它会发出 mousemove 事件。所以我所做的就是监视滚动,并监视鼠标移动。当用户滚动时,发生 mousemove 事件,然后我将其理解为 mouseup 事件。仅对 IE9 执行此检查,检查 proto 属性可用性。该代码也适用于 Opera,但 Opera 有 mouseup,当这两个事件发生时对我来说没有问题。这是代码,我编写 AngularJS + ZEPTO 代码,因此了解想法并编写自己的代码,不要指望直接复制并粘贴此代码:
正在与这个问题作斗争。我的系统也适用于移动设备,并且我有一个大的水平滚动,总是当用户停止滚动时,它需要找到正在查看的实际项目并将该项目集中在屏幕上(updatePosition)。希望这可以帮助你。这是为了支持 IE9+、FF、Chorme 和 Opera,我不担心旧浏览器。
此致
I was handling the same problem. For me IE9 don't emit mouseup event for scrollbars. So, I checked and on IE9 when you "mouseup" it emits a mousemove event. So what I did was monitor scrolling, and monitor mousemove. When user is scrolling, and a mousemove event happens, then I understand it as a mouseup event. Only do this check for IE9, cheching the proto property availability. The code will also run for Opera, but Opera has the mouseup and then no problem for me when both events happens. Here is the code, I write AngularJS + ZEPTO code, so get the idea and write your own code, don't expect to copy&paste this code directly:
Was fighting with this problem. My system also runs for mobile and I have a large horizontal scrolling, that always when user stop scrolling, it need to find the actual item the used is viewing and centralize this item on screen (updatePosition). Hope this can help you. This is to support IE9+, FF, Chorme and Opera, I'm not worrying with old browsers.
Best Regards
已经很晚了,但是......页面的任何部分都有任何滚动的解决方案......我用下一个代码来做......
Is very late but.... there are solution with any scroll in any part of your page.... I do it with the next code...