获取真实的 iPhone 分辨率 - jQuery

3
我正在编写一个jQuery插件,需要确切的屏幕分辨率。
众所周知,iPhone 4的响应是320*480,但我需要正确的尺寸(视网膜尺寸)。
当然,这个问题也存在于视网膜iPad上。
在这种情况下我该怎么办?
谢谢你们的回答。
/edit
好了,我已经完成了,但我认为有一个错误。
我的脚本:
var screenWidth = $(window).width() * window.devicePixelRatio;
var screenHeight = $(window).height() * window.devicePixelRatio;

i get the following values:
portrait:
screenWidth = 640
screenHeight = 960

landscape:
screenWidth = 960
screenHeight = 960

使用以下元标签:
meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no"
2个回答

2
在WebKit浏览器中,您可以使用window.devicePixelRatio来获取设备像素比。将其乘以分辨率,您应该就可以得到所需的数字。

谢谢您的回答,我更新了我的问题,但仍然存在问题。 - CaptainGerrard8
你的页面上是否有内容,以便 $(window).height() 实际上报告浏览器的完整高度而不仅仅是屏幕?尝试使用 screen.height * window.devicePixelRatio,看看是否可以获得更好的结果。 - Jason Whitted
1
屏幕高度没有起作用,但我犯了一些错误 你之前的解决方案完美地解决了问题 谢谢 - CaptainGerrard8

0

OP还提到了iPad。新的iPad mini具有1.5的设备像素比,因此乘以2会得到不正确的值。 - Jason Whitted
iPad mini 配备视网膜显示屏是从什么时候开始的? - Vytautas Butkus
从未错过任何有关 iPad mini 的消息 @Vytautas Butkus - CaptainGerrard8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接