定位 jquery UI 对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8010540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Position jquery UI dialog
提问by H Bellamy
How can I position the jquery UI dialog SPECIFICALLY, so that it goes to a position not defined by center, top, etc.
如何特定地定位 jquery UI 对话框,使其转到未由中心、顶部等定义的位置。
Thanks, I have tried to be as specific as posible.
谢谢,我已尽量做到具体。
回答by Guillaume Cisco
Using the position
option : http://jqueryui.com/position/
使用position
选项:http: //jqueryui.com/position/
Specifies where the dialog should be displayed. Possible values:
1) a single string representing position within viewport: 'center', 'left', 'right', 'top', 'bottom'.
2) an array containing an x,y coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100])
3) an array containing x,y position string values (e.g. ['right','top'] for top right corner).
指定应显示对话框的位置。可能的值:
1) 表示视口内位置的单个字符串:'center'、'left'、'right'、'top'、'bottom'。
2) 一个包含 x,y 坐标对的数组,以从视口左上角的像素偏移量(例如 [350,100])
3)一个包含 x,y 位置字符串值的数组(例如 ['right','top'] 用于右上角)。
For example : $( ".selector" ).dialog( "option", "position", [350,100] );
例如 : $( ".selector" ).dialog( "option", "position", [350,100] );
回答by camainc
This isn't an exact answer to your question, but you can mix 'top' with pixel values, like this:
这不是您问题的确切答案,但您可以将“顶部”与像素值混合,如下所示:
$('#widget').dialog({
position: ['top', 100]
});
This will position the dialog centered along the X axis, 100 pixels down from the top.
这将使对话框沿 X 轴居中放置,距顶部 100 像素。
回答by Michael R
If you want to use absolute positioning, the dialog's position
option is what you need. If you need to position relative to other elements, there's another easy technique you use, jquery UI's $('selector').position(options);
(seen at: http://jqueryui.com/demos/position/)
如果您想使用绝对定位,对话框的position
选项就是您所需要的。如果您需要相对于其他元素定位,您可以使用另一种简单的技术,jquery UI $('selector').position(options);
(见:http: //jqueryui.com/demos/position/)
For example:
例如:
// div to position against
var $div = $('#someDiv');
// Open dialog (positioning won't work on hidden elements)
$dialog.dialog('open');
// position newly opened dialog (using its parent container) below $div.
$dialog.dialog('widget').position({
my: "left top",
at: "left bottom",
of: $div
});