jqueryui对话框定位

发布于 2025-01-05 16:30:21 字数 396 浏览 1 评论 0原文

我正在使用 JQuery UI,并且希望将对话框水平居中但垂直位于中心上方,可能是固定数量的像素或距页面顶部的相对距离。有没有简单的方法可以做到这一点?看起来只有几个预定义的值,或者我可以使用精确的位置,但有没有一种简单的方法可以实现这一点?

 $("#dialog-form").dialog({
                autoOpen: false,
                width: 630,
                position: 'center',
                modal: true,
                resizable: false,
                closeOnEscape: false

            });

I am using JQuery UI and would like to position my dialog horizontally centered but vertically above center, maybe by a fixed amount of pixels or a relative distance from the top of the page. Is there an easy way to do this? It looks like there are just a couple pre-defined values or I can use an exact position but is there an easy way to accomplish this?

 $("#dialog-form").dialog({
                autoOpen: false,
                width: 630,
                position: 'center',
                modal: true,
                resizable: false,
                closeOnEscape: false

            });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

财迷小姐 2025-01-12 16:30:21

使用位置选项将对话框的顶部与窗口的顶部对齐(加上一个像素或百分比抵消)。

这应该使对话框水平居中,并将其放置在距顶部 150 像素的位置。

$("#dialog-form").dialog({
    autoOpen: false,
    width: 630,
    position: { my: 'top', at: 'top+150' },
    modal: true,
    resizable: false,
    closeOnEscape: false
});

旧版本的 jQuery UI 使用一个数组,其中包含 [x,y] 坐标对,以距视口左上角的像素偏移量表示(例如 [350,100])。

var dialogWidth = 630;
$("#dialog-form").dialog({
    // ...
    width: dialogWidth,
    position: [($(window).width() / 2) - (dialogWidth / 2), 150],
    // ...
});

Use the position option to align the top of the dialog with the top of the window (plus a pixel or percent offset).

This should center the dialog horizontally and position it 150 pixels from the top.

$("#dialog-form").dialog({
    autoOpen: false,
    width: 630,
    position: { my: 'top', at: 'top+150' },
    modal: true,
    resizable: false,
    closeOnEscape: false
});

Older versions of jQuery UI used an array containing an [x,y] coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100]).

var dialogWidth = 630;
$("#dialog-form").dialog({
    // ...
    width: dialogWidth,
    position: [($(window).width() / 2) - (dialogWidth / 2), 150],
    // ...
});
寂寞陪衬 2025-01-12 16:30:21

这对我有用

 position: { my: "center", at: "center", of: window },

你也可以在此处检查对话框位置
查找位置

This worked for me

 position: { my: "center", at: "center", of: window },

Also you can check dialog positions here
Find Position

晚风撩人 2025-01-12 16:30:21

我在搜索相同的问题时遇到了这个问题,但我已经有了答案:

position: ['center', 'top+100']

这将水平居中,距离顶部 100 像素,

这也可以

position: ['center', 'center+100']

水平居中,距离中心下方 100 像素

i came across this while searching for the same question bu i already had my answer :

position: ['center', 'top+100']

this will center horizontally and 100 pixel from top

this works also

position: ['center', 'center+100']

center horizontally and 100 pixel from below center

浊酒尽余欢 2025-01-12 16:30:21

我调整了 Exlord 的答案以适应。

position: ['center-7%', 'center-12%']

水平和垂直调整

$(".popup").dialog({    
position: ['center-7%', 'center-12%'],
title: 'Updating',
    width: "auto",
}
});

I adjusted Exlord's answer to fit.

position: ['center-7%', 'center-12%']

This adjusts horizontally and vertically

$(".popup").dialog({    
position: ['center-7%', 'center-12%'],
title: 'Updating',
    width: "auto",
}
});
各自安好 2025-01-12 16:30:21

试试这个:

    position: {
        my: 'top',
        at: 'top',
        of: $('#some-div')
    },

Try this:

    position: {
        my: 'top',
        at: 'top',
        of: $('#some-div')
    },
明月夜 2025-01-12 16:30:21
position: { 
   my: 'top', 
   at: 'top+150' 
}

为我工作。

position: { 
   my: 'top', 
   at: 'top+150' 
}

Worked for me.

殤城〤 2025-01-12 16:30:21

如果有人创建一个打开 jQuery 对话框的链接,因为该链接的具有点击事件处理程序,您可能会注意到它可能会跳转到页面顶部,但是在页面下方创建模式对话框,您必须滚动到它。

如果有人只是试图阻止 jQuery 对话框跳转到顶部,希望它停留在您单击的链接附近,只需删除 href 即可。试图解决这个问题几乎要发疯了。 HTML5 规范显然将 href=""href="#" 理解为移动到顶部。

If anyone is creating a link that opens a jQuery dialog due to the link's class having a click event handler, you may notice that it might jump to the top of the page but create the modal dialog deeper down the page and you have to scroll to it.

If anyone is just trying to stop the jQuery dialog from jumping to the top, wanting it to stay near the link you clicked, just remove href. Nearly went mad trying to solve this. The HTML5 specification apparently understands href="" or href="#" to mean move to the top.

纸短情长 2025-01-12 16:30:21

将 css 应用到 #dialog-form 中,

如果宽度 = 1000,则

使用 % 样本put

left:50%
左边距:-500px;

使其居中。或者你可以使用 iframe。

apply css into your #dialog-form use % sample

if width = 1000

put

left:50%
margin-left:-500px;

to make it centered. or you can use iframe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文