I want to vertically center a modal. If the window height is sufficient to require scrolling, the popup always appears near the top. This means I will need to scroll up to see it.
var winH = $(wi开发者_JS百科ndow).height(),
winW = $(window).width();
$(".popup").css('top', winH / 2 - $(".popup").height() / 2);
$(".popup").css('left', winW / 2 - $(".popup").width() / 2);
CSS:
.popup {
overflow:hidden;
position:absolute;
width:600px;
}
Just go with "position: fixed
".
Sounds like you already found your answer, but since I have it. Here's a working JS fiddle version: Live Version
精彩评论