简体   繁体   English

如何在屏幕中央显示模态弹出窗口,以及如何在调整屏幕大小时保持位置

[英]how to show an modal pop up in the center of screen and maintain the position on resizing the screen also

i have an modal pop up i am showing it in the middle of screen using javascript 我有一个模态弹出窗口,我正在使用javascript在屏幕中间显示它

$('div.openIDPopup').css({ 'height': $(document).height() + 'px',
        'width': $(window).width() + 'px',
        'visibility': 'visible'
    })
        .fadeIn('slow');
    $('div.openId').css({ 'visibility': 'visible',
        'top': ($(window).height() / 4) + 'px',
        'left': ($(window).width() / 3) + 'px'
    })
    .fadeIn('slow');

but on resizing the screen it is staying there as it is positioned absolutely how to get that feature. 但在调整屏幕大小时,它会停留在该位置,因为它已完全确定了如何获得该功能。

You might want to check out this CSS based solution: http://www.wpdfd.com/editorial/thebox/deadcentre4.html 您可能想看看这个基于CSS的解决方案: http : //www.wpdfd.com/editorial/thebox/deadcentre4.html

It relies on using a negative margin and I think it works great. 它依赖于使用负边距,我认为效果很好。

参见此处了解其操作方法: http//www.sohtanaka.com/web-design/examples/modal-window/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM