javascriptjquerycsstwitter-bootstraptwitter-bootstrap-3

Bootstrap modal: background jumps to top on toggle


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.


Solution

  • 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.