Jquery disable and enable scroll

$('.news-wrap').mouseenter(function(event) { $(window).mousewheel(function(event) { event.preventDefault(); }); }); 

Window scrolling is disabled, each element leaves the element. How to enable scrolling using mouseleave event?

+6
source share
2 answers

Like this?

 $('#abs').bind('mousewheel DOMMouseScroll', function(e) { var scrollTo = null; if (e.type == 'mousewheel') { scrollTo = (e.originalEvent.wheelDelta * -1); } else if (e.type == 'DOMMouseScroll') { scrollTo = 1000 * e.originalEvent.detail; } if (scrollTo) { e.preventDefault(); $(this).scrollTop(scrollTo + $(this).scrollTop()); } });​ 
+6
source

I wrote a jQuery plugin for this: $. disablescroll .

It stops scrolling from the mouse wheel, touch button, and buttons, such as Page Down .

 $('.news-wrap').mouseenter(function() { $(window).disablescroll(); }).mouseleave(function() { $(window).disablescroll("undo"); }); 

Hope someone finds this helpful.

+8
source

Source: https://habr.com/ru/post/916415/


All Articles