我正在阅读有关SO的许多问题,这些问题涉及以像素为单位检测屏幕尺寸的最佳方法,而最终取决于分辨率来找到实际的屏幕尺寸.
I was reading many questions on SO regarding best ways to detect screen size in pixels which is ultimately dependant on resolution to find the actual screen size.
我知道某些移动设备的屏幕很小(例如4英寸),但分辨率很高.尽管某些设备具有大屏幕(例如7英寸标签),但分辨率却很低.
I know some mobile devices have small screen (say 4inch) yet the resolution is high. While some devices r having large screen (say 7inch tab) yet the resolution is low.
因此,当您想向用户显示页面时,您确实需要屏幕尺寸(以英寸或厘米为单位),以提供最佳的视觉舒适感.
So when you want to display your page to the user, you really need the screen size in inches or centimetres to give the best view comforting the eyes.
所以我问: 是否可以找到设备的屏幕尺寸(英寸)而不是像素? 只要我们知道解决方案,我就知道可以! !Bec我们可以根据屏幕的宽度和高度来计算尺寸
So I ask: Is there away to find out screen size of the device in inches not pixels ? I know it can be, provided that we know the resolution! !Bec we can calculate the size from screen width and height
欣赏任何想法!
推荐答案一旦您获得了以像素为单位的屏幕分辨率,就可以使用隐藏的div计算出dpi了:
once you have got the screen resolution in pixels, you can work out the dpi with a hidden div:
<div id="dpi" style="height: 1in; width: 1in; left: 100%; position: fixed; top: 100%;"></div>js
var dpi_x = document.getElementById('dpi').offsetWidth; var dpi_y = document.getElementById('dpi').offsetHeight;然后以英寸为单位计算分辨率:
then work out the resolution in inches:
var width = screen.width / dpi_x; var height = screen.height / dpi_y;示例
更多推荐
使用javascript查找屏幕尺寸,以英寸为单位而不是像素
发布评论