Html 在不使用 jQuery 的情况下获取移动设备(尤其是 iPhone)上的窗口高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18243571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get window height on mobile devices (especially iPhones) without using jQuery
提问by Crashalot
All the answers on SO for fetching the device's height seem based on jQuery. We need something in pure JavaScript before the jQuery code loads.
关于获取设备高度的所有答案似乎都基于 jQuery。在加载 jQuery 代码之前,我们需要一些纯 JavaScript 的东西。
回答by Pete Scott
document.documentElement.clientHeight
There are a number of other methods, too: http://responsejs.com/labs/dimensions/
还有许多其他方法:http: //responsejs.com/labs/dimensions/
回答by jorgejeferson
May be a little late, but use window.screen.height
可能有点晚,但使用 window.screen.height
回答by NicolasBernier
In most cases, $(window).height();does the job. However, on iOS, it gives wrong results because of the toolbars, same as $(window).outerHeight();. The right value to use is window.outerHeight.
大多数情况下,$(window).height(); 做这项工作。但是,在 iOS 上,由于工具栏的原因,它给出了错误的结果,与$(window).outerHeight();相同 ;. 要使用的正确值是window.outerHeight。
Try this :
尝试这个 :
(typeof window.outerHeight != 'undefined')?Math.max(window.outerHeight, $(window).height()):$(window).height()