Detect retina displays with javascript
来源:互联网 发布:减肥过快皮肤松弛 知乎 编辑:程序博客网 时间:2024/06/11 21:59
用javascript检测是否是视网膜屏幕
I've been trying a way to detect a device's DPI for mobile design. While I haven't yet, I did at least find a way to detect whether the user is using a retina display. So without ado, here's how:
var retina = window.devicePixelRatio > 1 ? true : false;
Now the variable retina
will be set to true
if the user has a retina display. A simple if
statement can be used anywhere to execute code based on the user's display.
if (retina) { // the user has a retina display}else { // the user has a non-retina display}
Why?
A good is exam ple is if I have a 100x100 image (or video), the above code will tell me to upscale the image to 200x200 for it to look crisp on an iPhone 4 without forcing all users to unnecessarily download a 200x200 image. Especially given bandwidth is a major concern for mobile users.
if (retina) { var html = '<img src="my-high-res-image.jpg">';}else { var html = '<img src="my-low-res-image.jpg">';}
- Detect retina displays with javascript
- Detect CSS3 Support in Browsers with JavaScript
- javascript detect mobile device
- Android ListView with EditText loses focus when the keyboard displays
- Detect missing images with client-side script
- 2013 New MacbookPro With Retina 睡眠耗电严重–解决办法
- JavaScript Flash Detection Library (Flash Detect)
- javascript: detect mobile devices or browser
- javascript: detect mobile devices or browser
- First time play with JavaCV/OpenCV to detect faces
- How to detect Windows 64 bit platform with .net?
- How to Detect and Track Object With OpenCV
- Detect UI & Text Changes in DOM Tree with MutationObserver
- OpenCV_Corner Detect with FastFeatureDetector(基于FAST的角点检测)
- Javascript with
- retina与非retina
- javascript檢測瀏覽器和操作系統-detect.js
- Use javascript to detect the type of the file
- 使用 VMware Player 在 Ubuntu 下运行 Win
- 错误。。。
- oradim工具建立新的实例、启动实例、删除实例、删除监听服务
- 【学习点滴-数据结构-栈&队列】 栈的应用--递归的实现-汉诺塔
- FCK在线编辑器上传图片加入水印功能
- Detect retina displays with javascript
- Oracle10g数据类型总结
- 使用achartengine开发曲线图相关的Android应用程序
- error_mod_not_found
- Linux下stricmp在此作用域中尚未声明解决办法
- 无线路由器和猫连接不上解决方案
- 关于return false的事件
- 重定义malloc和free检测内存泄漏(转)
- 作为软件工程师,你必须知道的20个常识