Home > Web Front-end > CSS Tutorial > How to Programmatically Disable and Enable Page Scrolling with jQuery?

How to Programmatically Disable and Enable Page Scrolling with jQuery?

Barbara Streisand
Release: 2024-12-28 10:19:10
Original
255 people have browsed it

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',
});
Copy after login

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',
});
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template