gpt4 book ai didi

jquery - 放大/缩小时将 jquery 对话框保持在移动视口(viewport)的中心?

转载 作者:行者123 更新时间:2023-11-28 08:52:48 27 4
gpt4 key购买 nike

我正在尝试使移动视口(viewport)的 jquery 对话框中心特别是 iphone 的 safari,但是当用户尝试放大页面时,对话框会移动到页面的右下角,这使得它不再可见。

代码如下:

//-- The dialog
$("#dialog").dialog({
modal:true,
draggable:true,
resizable:false,
width:650,
height:330,
cache:false,
position:'center'
});

//-- Make dialog center when page resize
$(window).resize(function() {
$(".ui-dialog-content").dialog("option", "position", "center");
});

这在 PC 浏览器中完美运行,但对于移动设备,它仅在页面缩小时有效。

知道怎么做吗?

最佳答案

这听起来像是 jQueryUI 的问题。

您是否尝试过这样的 CSS 替代方案:

JS

$("#dialog").dialog({
modal:true,
draggable:true,
resizable:false,
width:650,
height:330
});

CSS

.ui-dialog {
left: 50% !important;
top: 50% !important;
margin-left: -325px !important; // half 650
margin-top: -165px !important; // half 330
}

我使用 !important 来覆盖 jQueryUI CSS 文件中定义的默认值。

关于jquery - 放大/缩小时将 jquery 对话框保持在移动视口(viewport)的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143281/

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