2

Is it possible to remove scroll of body page when a modal window is opened from css?
For example my body page has a height:200% so if I want to go on the bottom of page I must use scroll (overflow-y:auto). Now if I will open a modal window the scroll of body page remain active and I want it be disabled when a modal window is opened.

Thank you.

2
  • 1
    If you use position:fixed for the modal window it will remain in place on the screen even if the user scrolls up or down. Commented Feb 16, 2012 at 10:25
  • Yes , I know I already have position:fixed on modal but I want to disable scroll of body page. Commented Feb 16, 2012 at 10:29

4 Answers 4

3

If you are opening a modal window when a link is click you can do the following:

// modal screen activate $('a').live('click', function(){ modalScreen.show(); $('body').css('overflow','hidden'); }); // modal screen de-activate $('body, html').live('click', function(){ modalScreen.hide(); $('body').css('overflow','auto'); }); 
Sign up to request clarification or add additional context in comments.

Comments

0

I assume you are opening your lightwindow using javascript:

You could than just set the height of the body to 100% and set overflow-y to hidden. That will remove the scrollbar.

You will have to reset everything on close of the lightwindow.

2 Comments

I use wicket, and yes in back of modal window is a mega javascript, I prefer to not modify that. For that reason I try to find a way to disable overflow for body page with css or jQuery.
You can set any css you want using jQuery: $('body').css({'height': '100%', 'overflow-y': 'hidden'}); Something like that should do the trick (untested).
0

Use position:fixed and set your left and top to percentages, then margin-left to a negative value of the width in pixels. e.g. width: 700px; left: 50%, margin-left: -350px; in order to center horizontally.

Comments

0

Or just add and remove classes to your script:

$('body').addClass('modal-open'); //when modal is open $('body').removeClass('modal-open'); //when modal is closed 

Then you can go to your css file and add multiple css styles. For hiding the scroll bar use:

.modal-open { overflow: hidden; } 

Especially when you want to change more things I prefer this way, but that's my opinion. Use whatever you like!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.