Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock scrolling of a web page temporarily?

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 ?

like image 261
Rajat Gupta Avatar asked Jun 20 '11 12:06

Rajat Gupta


People also ask

How do I lock my browser scroll?

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.

How do I restrict scrolling in HTML?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.


1 Answers

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'});
like image 181
Limpan Avatar answered Sep 21 '22 13:09

Limpan