[英]Can I test retina devices by setting content css property with media queries?
Does anyone see anything wrong with setting the content
css property on body
when on retina device for the purpose of running retina-specific js? 在运行视网膜特定js的视网膜设备上,是否有人在
body
上设置content
css属性有什么问题?
This seems to me like the simplest, lightest, cross-browser solution for testing for retina devices. 在我看来,这似乎是用于测试视网膜设备的最简单,最轻便的跨浏览器解决方案。 At least it's worked for me...
至少对我有用...
CSS: CSS:
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
body {
content: 'retina'
}
}
Test with jQuery: 用jQuery测试:
var isRetina = $('body').css('content') == 'retina';
Use window.devicePixelRatio
. 使用
window.devicePixelRatio
。 If it more than 1 - it's retina
display. 如果大于1,
retina
显示。
For IE 10+ (which IE are available on tablets and smartphones) you can relay on screen.deviceXDPI
and screen.logicalXDPI
: 对于IE 10+(平板电脑和智能手机可使用IE),您可以在
screen.deviceXDPI
和screen.logicalXDPI
上进行中继:
window.devicePixelRatio = window.devicePixelRatio ||
window.webkitDevicePixelRatio ||
screen.deviceXDPI/screen.logicalXDPI ||
1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.