简体   繁体   English

在 ES6 中可靠地确定全屏尺寸

[英]Reliably determining full screen size in ES6

I have a in my document which I scale to full screen using the full screen JS API div.fullscreenRequest().我的文档中有一个我使用全屏 JS API div.fullscreenRequest() 缩放到全屏。 I find out how large the full screen actually is only after it has been activated, ie, the fullscreenchange event has fired.我只有在激活后才知道全屏实际上有多大,即 fullscreenchange 事件已触发。 In this event, I make some computations (original size of div versus new scaled-up size) so I can apply some transformations to the div to make it look right.在这种情况下,我进行了一些计算(div 的原始大小与新的放大大小),以便我可以对 div 应用一些转换以使其看起来正确。

The issue I am having is that determining the full screen size is highly unreliable.我遇到的问题是确定全屏尺寸非常不可靠。 In the fullscreenchange event, if I do detect that the full screen mode has been activated, and I use screen.width and screen.height, respectively, I sometimes get the correct values back (1920 x 1080) but sometimes I get 1920 x 948 for no apparent reason, non-deterministically.在 fullscreenchange 事件中,如果我确实检测到全屏模式已被激活,并且我分别使用 screen.width 和 screen.height,我有时会得到正确的值 (1920 x 1080) 但有时我会得到 1920 x 948没有明显的原因,非确定性的。 It appears that the event fires in some sort of racy way while the screen is still switching to full screen mode?当屏幕仍在切换到全屏模式时,事件似乎以某种方式触发?

What is the reliable way of determining the full screen resolution?确定全屏分辨率的可靠方法是什么?

What about this:那这个呢:

 const width = window.screen.width * window.devicePixelRatio, height = window.screen.height * window.devicePixelRatio; console.log("screen size:", width + "x" + height);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM