Alex Rivera | Logout

Set modal layer to the center fo the viewed screen

Asked 2012-10-17T09:24:13.440
15

I'm using Twitter Bootstrap's modal, but I had to change their position to absolute, be cause I need them to be able to scroll cause of the small screens. Sadly, with this, the modals open to a fixed position of the site and not on the viewed area. Is there any way to open them (and be able to be scrolled) to the screen what I'm currently viewing?

Picture of my problem

CSS:

.modal {
    width: 845px;
    margin: -250px 0 0 -430px;
    background-color: #f6f5ed;
    position: absolute;
    border: 1px solid #cdc4b2;
    top: 50%;
    left: 50%;
}
Edit
Report

1 Answer

15

This thread: Modal plugin of Bootstrap 2 is not displayed by the center has the correct answer, posted here as well:

   $('#YourModal').modal().css(
            {
                'margin-top': function () {
                    return window.pageYOffset-($(this).height() / 2 );
                }
            });
answered 2013-02-06T22:10:33.037

Your Answer