定位 jQuery 对话框
I want to position my jQuery dialog x-pixels away from the right border of the browser. Is this anyhow possible?
http://jqueryui.com/demos/dialog/
The position option doesn't seem to have that kind of setup, but is there any other way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这使对话框 div 保持在固定位置,
这对我在 IE FF chrome 和 safari 中有效,只需调用
当您想要打开对话框时,
This keeps dialog div in fixed position
this works for me in IE FF chrome and safari
when you want dialog box open just call
如果您将对话框设置为
position:absolute
,那么它会采用常规页面流,并且您可以使用left
和top
属性将其放置在页面上的任何位置。并将 myPosition css 类定义为:
您可以设置
top
、left
、right
和bottom
myPosition
的属性,使用长度(例如以像素或百分比为单位)。If you make your dialog box's
position:absolute
, then its taken about of the regular page flow, and you can use theleft
andtop
property to place it anywhere on the page.and define the myPosition css class as:
You can set the
top
,left
,right
, andbottom
properties formyPosition
using either a length such as in pixels or percentage.大多数答案对我来说似乎都是解决方法,我想找到官方的 jQuery 方法来做到这一点。在阅读了
.position()
文档后,我发现它确实可以在 jQuery 小部件的初始化中完成:其中 +100 分别是距右侧和顶部的距离
Most of these answers seemed to be workarounds to me, and I wanted to find the official jQuery way to do it. After reading through the
.position()
docs, I found that it can indeed be done in the initialization of the jQuery widget:Where the +100 is the distance from the right and top respectively
我知道答案已被接受,但以防万一有人需要更多信息:
http://salman-w.blogspot.co .uk/2013/05/jquery-ui-dialog-examples.html
I understand the answer is already accepted but just in case if any one need more info:
http://salman-w.blogspot.co.uk/2013/05/jquery-ui-dialog-examples.html
使用此代码,您可以指定顶部和左侧位置:
with this code u can specify ur top and left position:
看这里:http://jqueryui.com/demos/dialog/#option-position
使用指定的位置选项初始化对话框。
初始化后获取或设置位置选项。
look here: http://jqueryui.com/demos/dialog/#option-position
Initialize a dialog with the position option specified.
Get or set the position option, after init.
这对我有用,以 10px 偏移在右上角显示对话框:
position: "right-10 top+10"
:This worked for me to display the dialog at the top-right corner with 10px offset:
position: "right-10 top+10"
:为了固定中心位置,我使用:
To fix center position, I use: