jqueryui对话框定位
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用位置选项将对话框的顶部与窗口的顶部对齐(加上一个像素或百分比抵消)。
这应该使对话框水平居中,并将其放置在距顶部 150 像素的位置。
旧版本的 jQuery UI 使用一个数组,其中包含 [x,y] 坐标对,以距视口左上角的像素偏移量表示(例如 [350,100])。
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.
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]).
这对我有用
你也可以在此处检查对话框位置
查找位置
This worked for me
Also you can check dialog positions here
Find Position
我在搜索相同的问题时遇到了这个问题,但我已经有了答案:
这将水平居中,距离顶部 100 像素,
这也可以
水平居中,距离中心下方 100 像素
i came across this while searching for the same question bu i already had my answer :
this will center horizontally and 100 pixel from top
this works also
center horizontally and 100 pixel from below center
我调整了 Exlord 的答案以适应。
position: ['center-7%', 'center-12%']
水平和垂直调整
I adjusted Exlord's answer to fit.
position: ['center-7%', 'center-12%']
This adjusts horizontally and vertically
试试这个:
Try this:
为我工作。
Worked for me.
如果有人创建一个打开 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 understandshref=""
orhref="#"
to mean move to the top.将 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.