Home >Web Front-end >CSS Tutorial >How to Programmatically Disable and Enable Page Scrolling with jQuery?
Disable Page Scrolling Programmatically with jQuery
To disable scrolling of the body using jQuery, you can leverage the following solution:
$('html, body').css({ overflow: 'hidden', });
This sets the overflow property of the HTML and body elements to "hidden," effectively preventing the page from scrolling.
To restore scrolling, you can set the overflow property back to "auto":
$('html, body').css({ overflow: 'auto', });
This approach is tested and confirmed to work in both Firefox and Chrome. It provides a simple and effective way to disable page scrolling programmatically.
The above is the detailed content of How to Programmatically Disable and Enable Page Scrolling with jQuery?. For more information, please follow other related articles on the PHP Chinese website!