Victor
Victor

Reputation: 1271

Possible to disable scrollbar instead of hiding?

I was wondering if it is possible to disable a scrollbar instead of hiding it on a page? I want it to stay on the page when I open a modal dialog, I just don't want the users to be able to scroll the main page. So the perfect functionality would be:

short page - no scrollbar at all;

long page - scrollbar appears;

long page modal dialog open - scrollbar still there, but cannot be used.

Upvotes: 3

Views: 1804

Answers (2)

Naftali
Naftali

Reputation: 146350

Well when you have a modal you can just play around with the onscroll of window

Fiddle: http://jsfiddle.net/maniator/DmmEv/

Code:

var scrollX = window.scrollX, scrollY = window.scrollY;
window.onscroll = function(e){
    scroll(scrollX,scrollY)
}

Real Example:
Scrollbars will stay in place after clicking on Click Me
Fiddle: http://jsfiddle.net/maniator/DmmEv/6/

Upvotes: 3

Mike Christensen
Mike Christensen

Reputation: 91696

Maybe try:

<body style="overflow: scroll;">
Hello
<body>

Upvotes: -1

Related Questions