Home >Web Front-end >CSS Tutorial >How Can I Programmatically Disable and Re-enable Page Scrolling with jQuery?
Programmatic Page Scrolling Disabling with jQuery
In JavaScript, disabling page scrolling is a common task. One approach involves utilizing jQuery's CSS manipulation capabilities. This method requires three steps:
An Alternative Approach
The provided approach effectively prevents page scrolling. However, there is a simpler and more comprehensive solution:
$('html, body').css({ overflow: 'hidden', height: '100%' });
This code fully disables page scrolling by setting both the html and body tags to have hidden overflow and a fixed height of 100%. To restore scrolling, simply reset the CSS properties to their original values.
$('html, body').css({ overflow: 'auto', height: 'auto' });
This solution has been tested and confirmed to work effectively in both Firefox and Chrome browsers.
The above is the detailed content of How Can I Programmatically Disable and Re-enable Page Scrolling with jQuery?. For more information, please follow other related articles on the PHP Chinese website!