在 javascript 中获取与方向相关的屏幕尺寸 (iPad)

Getting the orientation dependent screen dimensions (IPad) in javascript

本文关键字:屏幕 iPad javascript 获取 方向      更新时间:2023-09-26

我正在尝试获取iPad上的屏幕尺寸。

$wnd.屏幕宽度$wnd.屏幕高度

当我处于横向模式时,尺寸返回 768x1024。 这不是我所期望的。 如何获得 1024x768 的真实尺寸?

注意:我没有改变方向,我从横向模式开始并保持在该模式下。

作为最简单的解决方案,如果宽度小于高度,则交换宽度和高度,以便始终获得横向模式的分辨率。

function getResolution(){
    return {
        width: $wnd.screen.width < $wnd.screen.height
             ? $wnd.screen.height
             : $wnd.scree.width,
        height: $wnd.screen.height > $wnd.screen.width
             ? $wnd.screen.width
             : $wnd.scree.height
    };
}

iPad 喜欢在你改变方向时做一些有趣的缩放。

您可以使用<meta viewport>标签解决其中的许多问题,例如:

<meta name="viewport" content="user-scalable=no,initial-scale=1.0,
 minimum-scale=1.0,maximum-scale=1.0">