Is there a beforeScroll event in jQuery? Or can this type of event be replicated at all?
We have a scenario where we need perform an event before a div with overflow:scroll has been scrolled. The problem with using the .scroll event is that this is raised after the div has been scrolled rather than before.
Is there a beforeScroll event in jQuery? Or can this type of event be replicated at all?
We have a scenario where we need perform an event before a div with overflow:scroll has been scrolled. The problem with using the .scroll event is that this is raised after the div has been scrolled rather than before.
Share Improve this question asked Jul 28, 2010 at 10:55 Robert WRobert W 2,9617 gold badges34 silver badges42 bronze badges 1- 2 You mean after the scroll is performed but before the actual scrolling has occured? – David Hellsing Commented Jul 28, 2010 at 11:03
2 Answers
Reset to default 6No, there's no such event. The scroll event cannot be cancelled (for obvious reasons) and I would speculate that it fires after the action so that the scrollTop and scrollLeft properties are accurate when accessed.
Possible workarounds might be to capture the mousewheel/DOMMouseScroll events and the keydown events for page up, page down, up, down, etc. keys. There's no 100% method, though - you'll never be able to stop the user from interacting with the browser's scrollbar ponents. The only true solution there is to roll your own scrollbars.
If you're just looking to find the amount the user scrolled, you could set a timer to store the current scrollLeft/scrollTop in a variable and then check them vs the new values in the scroll event.
I solved this in a crude way that turned out to be surprisingly un-laggy:
I update the position myself after checking that the position is within the range that I want, using position=fixed, and alter the top value.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744178997a4561892.html
评论列表(0条)