简体   繁体   中英

How to make a floating div consume all mouse scroll events

I have a div that is scrolling vertically. I, however, really want it to consume all mouse scroll events, so that while it is visible and "in focus" I don't want the whole page scrolling while the user is just trying to scroll this sub-section.

Can this be achieved in html/css/js?

I assume a possible strategy would be to add an event listener, listen to mouse scroll events, and when you know you are at the top/bottom to just consume them. Is there an easier way?

Would this jQuery plugin do the trick?

http://www.protofunc.com/scripts/jquery/mwheelIntent/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM