How can I lock scrolling of a webpage temporarily when a dialog box is displayed ? I have a dialog box within which I want to enable scrolling after deactivating scrolling from the overlayed webpage.
Is there a js command to temporarily disable scrolling ?
Look at your computer keyboard and locate the "Scroll Lock" key at the top, between the "Print Screen" and "Pause/Break" buttons. Click the "Scroll Lock" key and lock the scroll lock bar. When you lock the scroll bar, a small light appears on your keyboard.
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.
EDIT Try this:
On dialog open (remove scrollbar and prevent user from scrolling):
$('body').css({'overflow':'hidden'});
$(document).bind('scroll',function () {
window.scrollTo(0,0);
});
On Dialog Close(allow user to scroll again):
$(document).unbind('scroll');
$('body').css({'overflow':'visible'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With