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
Barbara StreisandOriginal
2024-12-28 10:19:10199browse

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!

Statement:
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