gpt4 book ai didi

jquery - 如果调整高度,模式弹出窗口将适合浏览器 View

转载 作者:行者123 更新时间:2023-12-01 08:21:27 25 4
gpt4 key购买 nike

我已经阅读了本教程来制作模式弹出窗口,它似乎非常适合我需要做的事情。但是,我想知道是否有人可以帮助我弄清楚我需要计算什么来更改对话框,以便每当您调整浏览器大小时它都会跟随。本教程很好,因为如果您调整浏览器的大小(宽度方向),该框将跟随并进入中间。但如果是高度的话,就不会了。

教程:Here

我认为这与这些代码有关:

    // get the screen height and width  
var maskHeight = $(document).height();
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogTop = (maskHeight/3) - ($('#dialog-box').height()/3);
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

// assign values to the overlay and dialog box
$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();

我尝试使用 $(window).height() 但我认为这也不起作用。我试图模仿宽度样式,因为它可以工作,但它似乎不适用于高度?有人可以帮我解决这个问题吗?

谢谢!

最佳答案

试试这个

工作 demo 。您可以调整窗口大小并尝试将对话框自动重新定位到中心。

$(function(){
$(window).resize(function(){
// get the screen height and width
var maskHeight = $(window).height();
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogTop = (maskHeight - $('#dialog-box').height())/2;
var dialogLeft = (maskWidth - $('#dialog-box').width())/2;

// assign values to the overlay and dialog box
$('#dialog-overlay').css({ height:$(document).height(), width:$(document).width() }).show();
$('#dialog-box').css({ top: dialogTop, left: dialogLeft, position:"fixed"}).show();
}).resize();
});

关于jquery - 如果调整高度,模式弹出窗口将适合浏览器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7143333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com