Febin J S
Febin J S

Reputation: 1368

How to avoid scroll bar in all browsers while a jQuery Dialog box is showing?

I have a page where when we click a button a Jquery dialog box is called using JQuery. But when it is shown the Window scroll bar is shown in all browsers. How can we avoid this? Can we avoid this uising JQuery? Or is it is better to fix by CSS?.

Upvotes: 0

Views: 623

Answers (2)

Gary Green
Gary Green

Reputation: 22395

Just set the overflow on the body tag to hidden, should do the trick:

$('body').css('overflow', 'hidden');

Fiddle: http://jsfiddle.net/garreh/xYatB/1/

Upvotes: 1

Val
Val

Reputation: 17532

css

.hidescrolls {
  overflow:hidden;
}

JQ

...click(function (){
   // show dialog();
   $('body,html').addClass('hidescrolls');
});

make sure you use the $('body,html').removeClass('hidescrolls'); on dialog close/hide

Upvotes: 3

Related Questions