如何使用jQuery垂直放置模式中心,而与滚动高度无关? [英] How do I vertically center a modal using jQuery, independent of scrolling height?

查看:49
本文介绍了如何使用jQuery垂直放置模式中心,而与滚动高度无关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使模态垂直居中.如果窗口高度足以要求滚动,则弹出窗口始终显示在顶部附近.这意味着我需要向上滚动才能看到它.

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 = $(window).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;
}

推荐答案

只需使用"position: fixed"即可.

这篇关于如何使用jQuery垂直放置模式中心,而与滚动高度无关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆