I want my body to stop scrolling when using the mousewheel while the Modal (from http://twitter.github.com/bootstrap) on my website is opened.
I've tried to call the piece of javascript below when the modal is opened but without success
$(window).scroll(function() { return false; });
AND
$(window).live('scroll', function() { return false; });
Please note our website dropped support for IE6, IE7+ needs to be compatible though.
You could use the following logic, I tested it and it works(even in IE)
The best solution is the css-only
body{overflow:hidden}
solution used by most of these answers. Some answers provide a fix that also prevent the "jump" caused by the disappearing scrollbar; however, none were too elegant. So, I wrote these two functions, and they seem to work pretty well.Check out this jsFiddle to see it in use.
Hope this helps...
Most of the pieces are here, but I don't see any answer that puts it all together.
The problem is threefold.
(1) prevent the scroll of the underlying page
(2) and remove the scroll bar
(3) clean up when the modal is dismissed
If the modal is not full-screen then apply the .modal bindings to a full screen overlay.
Try this one:
it worked for me. (supports IE8)
Simply hide the body overflow and it makes body not scrolling. When you hide the modal, revert it to automatic.
Here is the code: