1

The issue I'm having is that when a modal is opened, the background body is scrollable using the mouse wheel. Seems like this problem is known and people have suggested to set the body to overflow:hidden as stated in this link: Prevent BODY from scrolling when a modal is opened which works fine if your page is short and the modal link is on the initial visible page. However, if you have a longer page and you have to scroll down to see the modal link, once you click to open the modal, the background body shifts to the top.

The background does not scroll anymore, which is what I want, but is there any way to prevent it from popping back to the top when the modal is opened? It's inconvenient when you need to add multiple entries of something using the modal and you have to keep scrolling down to click the modal link to add another item.

Community
  • 1
  • 1
Guest
  • 381
  • 2
  • 7
  • 20
  • *"the background shifts to the top"* - That isn't current behavior in Bootstrap. What version are you using? Please provide an example. For instance, here's a [working JSFiddle w/ latest Bootstrap](http://jsfiddle.net/mmfansler/yPmLr/) which doens't exhibit the behavior you describe. – merv Apr 26 '13 at 20:58
  • Possible duplicate: http://stackoverflow.com/q/12894570/570918 – merv Apr 26 '13 at 20:59

2 Answers2

0

In your onclick(I'm guessing you use onclick) event-method insert a return false; at the end, that will prevent the site from scrolling to the top.

olsn
  • 15,273
  • 5
  • 51
  • 61
  • Twitter Bootstrap automatically takes care of all the javascript for modals. All we have to do is add a data-toggle="modal" and the modal reference in the href in the link. Is there any other way? – Guest Apr 26 '13 at 20:01
  • My other idea would be that you post the source or a link to the case – olsn Apr 26 '13 at 20:21
  • It helped me. I use on click to open modal window. – Timur Samkharadze Apr 01 '14 at 08:11
0

I was having a similar problem in which modals larger than the window were cut off, and scrolling anywhere would scroll the background and not the modal.

This question pointed me to this plugin which is simple to use and fully addresses mine in addition to your problem of not permitting the background to scroll:

However this issue is said to be resolved in Bootstrap 3 and the plugin should not be needed if you're using the current version of Bootstrap.

Community
  • 1
  • 1
casaram
  • 444
  • 3
  • 10