将 xul 对话框置于屏幕中央
在对话框中,我调整了一些图像的大小,然后强制窗口调整为 sizeToContent。然后,我希望对话框能够以屏幕为中心。我该怎么做?
In a dialog, I resize some images and then force the window to sizeToContent. Then, I want the dialog to center itself to the screen. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还四处寻找并在 MDC 中寻找任何可以将其居中的东西,但什么也没找到,所以我创建了这个!这适用于窗口和对话框。
您唯一需要更改的是将
windowID
更改为窗口的 ID 值。它将适用于所有屏幕分辨率,因为它需要总屏幕宽度和高度,然后将其分成两半,从而给出屏幕的中心,然后减去您的宽度和高度设置以将它们考虑在内,但也将它们除以一半以进行偏移窗口如果没有偏移,就不会居中。
我希望这有帮助!
I also searched around and looked to the MDC for anything which would center it but found nothing so I created this! This will work both on window and dialog.
The only thing you must change is
windowID
to the ID value of your window.It will work on all screen resolutions as it takes the total screen width and height then divides it in half thus giving the center of the screen then it subtracts your width and height settings to take them into account but divides them by half as well to offset the window as without the offset it will not be centered.
I hope this has helped!
最终的结果是一个可以自行移动的窗口?请不要让它太烦人:)
无论如何,您必须使用
window.moveTo
和各种screen
属性手动执行此操作(请参阅https://developer.mozilla.org/en/DOM/window)这是一个有趣的例子,尽管它没有不要将窗口居中,它确保它是可见的:
http://www.koders.com/javascript/fid3F51B87DFD457428278627805CCA8D39ADC 13455.aspx? s=窗口#L3
The end result would be a window that moves itself? Please don't make it too annoying :)
Anyway, you'll have to do it manually using
window.moveTo
and variousscreen
properties (see https://developer.mozilla.org/en/DOM/window)Here's an interesting example, although it doesn't center the window, it ensures it's visible:
http://www.koders.com/javascript/fid3F51B87DFD457428278627805CCA8D39ADC13455.aspx?s=window#L3
元素为您定义 moveToAlertPosition() 和 centerWindowOnScreen() 便捷方法,并将它们复制到全局范围,这样您就不必使用 document.documentElement 来确定它们的范围。A
<dialog>
element defines the moveToAlertPosition() and centerWindowOnScreen() convenience methods for you, and also copies them to the global scope so you don't have to scope them with document.documentElement.