Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant stop page scroll with e.preventDefault(); [duplicate]

Tags:

jquery

I want to completely disable scrolling on the page with jquery (NOT body overflow:hidden).

I thought this would work but for some reason it doesn't.

$( window ).on( "scroll", function(e) {
        e.preventDefault();
    });
like image 749
dzimi Avatar asked Jun 10 '16 21:06

dzimi


People also ask

How do I stop Div scrolling?

The scroll bars in the example URL are in the body, so you need to set the overflow property on the body to hidden when the menu is open and to auto when the menu is closed. In the JavaScript file, you can add jQuery(document. body).

How do I stop parent scrolling element?

To do this (in Chrome, Firefox, and Edge), we can add the CSS property overscroll-behavior: contain to the overflow: auto element. This will prevent the "scroll chaining" behavior, which will, in turn, keep the mouse-wheel active within the target element.

How do you stop scrolling in CSS?

Disabling scroll with only CSS. There's another way to disable scrolling that is commonly used when opening modals or scrollable floating elements. And it is simply by adding the CSS property overflow: hidden; on the element you want to prevent the scroll.


1 Answers

I tried doing the same thing a month ago and managed to get it working like described here

like image 85
ga.breban Avatar answered Nov 15 '22 21:11

ga.breban