3

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.

Victor
  • 1,191
  • 5
  • 18
  • 42
  • possible duplicate of [Disable browsers vertical and horizontal scrollbars](http://stackoverflow.com/questions/242608/disable-browsers-vertical-and-horizontal-scrollbars) – Naftali aka Neal Oct 24 '11 at 15:55
  • 1
    I don't want to hide the scrollbar because it creates a page shift by the scrollbar width. If possible, I'd like to disable it, grey out or whatever is possible. – Victor Oct 24 '11 at 15:58
  • http://stackoverflow.com/questions/8701754/just-disable-scroll-not-hide-it – Yousef Salimpour Aug 26 '14 at 10:22

2 Answers2

3

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/

Naftali aka Neal
  • 138,754
  • 36
  • 231
  • 295
-1

Maybe try:

<body style="overflow: scroll;">
Hello
<body>
Mike Christensen
  • 77,193
  • 46
  • 189
  • 300
  • 1
    Woudln't it make the scrollbar appear at all times? I don't really want it to be there where the page is short. or would it be still possible for the users to use it when a modal dialog appears? – Victor Oct 24 '11 at 15:58
  • Oh I thought that's what you wanted. Okay so change `scroll` to `auto` – Mike Christensen Oct 24 '11 at 15:59
  • thanks for the suggestion, it works in FF, but users are still able to use scrollbar in older IE. – Victor Oct 24 '11 at 16:01
  • I guess I'm not following what you want. Do you want to show the scrollbars or not? – Mike Christensen Oct 24 '11 at 16:21
  • like I mentioned in the question. I don't want the scrollbar to show when the page is short, and I want it to show when it's long, but I want the scrollbar to be disabled when a modal dialog opens up on a long page with a scrollbar. hope that's clear :) – Victor Oct 24 '11 at 17:00