在不使用jQuery的情况下获取移动设备(尤其是iPhone)上的窗口高度

Get window height on mobile devices (especially iPhones) without using jQuery

本文关键字:iPhone 尤其是 高度 窗口 移动 jQuery 情况下 获取      更新时间:2023-09-26

SO上获取设备高度的所有答案似乎都基于jQuery。在加载jQuery代码之前,我们需要一些纯JavaScript的东西。

document.documentElement.clientHeight

还有许多其他方法:http://responsejs.com/labs/dimensions/

可能有点晚,但使用window.screen.height

在大多数情况下,$(window).height()完成任务。然而,在iOS上,由于工具栏的原因,它给出了错误的结果,与$(window).outerHeight()。要使用的正确值是window.outerHeight.

试试这个:

(typeof window.outerHeight != 'undefined')?Math.max(window.outerHeight, $(window).height()):$(window).height()