Bootstrap modal: background jumps to top on toggle

FooBar picture FooBar · Feb 6, 2014 · Viewed 91k times · Source

I have a problem, with a modal. I have a button on a page, that toggles the modal. When the modal shows up, the page jumps to top.

I have done everything I could to find a solution/etc, but I am really lost.

EDIT:

I have also tried with: $('#myModal').modal('show'); but it has the exact same effect.

Answer

pstenstrm picture pstenstrm · Feb 19, 2014

When the modal opens a modal-open class is set to the <body> tag. This class sets overflow: hidden; to the body. Add this rule to your stylesheet to override the bootstrap.css style:

body.modal-open {
    overflow: visible;
}

Now the scroll should stay in place.