将 xul 对话框置于屏幕中央

发布于 2024-08-08 12:02:28 字数 73 浏览 10 评论 0原文

在对话框中,我调整了一些图像的大小,然后强制窗口调整为 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 技术交流群。

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

发布评论

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

评论(3

好倦 2024-08-15 12:02:28

我还四处寻找并在 MDC 中寻找任何可以将其居中的东西,但什么也没找到,所以我创建了这个!这适用于窗口和对话框。

var w=(screen.availWidth/2)-(document.getElementById('windowID').width/2);

var h=(screen.availHeight/2)-(document.getElementById('windowID').height/2);

window.moveTo(w,h);

您唯一需要更改的是将 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.

var w=(screen.availWidth/2)-(document.getElementById('windowID').width/2);

var h=(screen.availHeight/2)-(document.getElementById('windowID').height/2);

window.moveTo(w,h);

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!

日裸衫吸 2024-08-15 12:02:28

最终的结果是一个可以自行移动的窗口?请不要让它太烦人:)

无论如何,您必须使用 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 various screen 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

眼角的笑意。 2024-08-15 12:02:28

元素为您定义 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.

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