使用 jQuery 获取原生屏幕分辨率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14010477/
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 native screen resolution using jQuery
提问by thomas-hiron
I'd like to get the native screen width on a device to append scripts in the DOM. Is it possible using jQuery ?
我想获得设备上的本机屏幕宽度以在 DOM 中附加脚本。可以使用 jQuery 吗?
Thanks
谢谢
回答by Christian
window.screen.width
? Source: https://developer.mozilla.org/en-US/docs/DOM/window.screen
window.screen.width
? 来源:https: //developer.mozilla.org/en-US/docs/DOM/window.screen
回答by BenM
Sure. You can get the basic width and height using:
当然。您可以使用以下方法获取基本宽度和高度:
screen.width;
screen.height;
If required, you can also get the pixel ratio (useful if you need to also detect retina displays) by using:
如果需要,您还可以使用以下方法获取像素比(如果您还需要检测视网膜显示,则很有用):
window.devicePixelRatio
回答by asgoth
You can set the width to device width with a css property:
您可以使用 css 属性将宽度设置为设备宽度:
width: device-width;
回答by ATOzTOA
You should use:
你应该使用:
window.screen.availHeight
window.screen.availWidth