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.
Hiding the overflow and fixing the position does the trick however with my fluid design it would fix it past the browsers width, so a width:100% fixed that.
Many suggest "overflow: hidden" on the body, which will not work (not in my case at least), since it will make the website scroll to the top.
This is the solution that works for me (both on mobile phones and computers), using jQuery:
This will make the scrolling of the modal to work, and prevent the website from scrolling at the same time.
My solution for Bootstrap 3:
because for me the only
overflow: hidden
on thebody.modal-open
class did not prevent the page from shifting to the left due to the originalmargin-right: 15px
.I am using this vanilla js function to add "modal-open" class to the body. (Based on smhmic's answer)
If modal are 100% height/width "mouseenter/leave" will work to easily enable/disable scrolling. This really worked out for me: