How to target retina devices with Modernizr
/**
* Modernizr test for retina / high resolution / high pixel density
*
* @author Joao Cunha
* @license MIT
*/
Modernizr.addTest('hires', function() {
// starts with default value for modern browsers
var dpr = window.devicePixelRatio ||
// fallback for IE
(window.screen.deviceXDPI / window.screen.logicalXDPI) ||
// default value
1;
return !!(dpr > 1);
});Written by João Cunha
Related protips
1 Response
Thank you for sharing. I've got just a question: why are you writing !!(condition) ?
Wouldn't it be the same of (condition)?
Thanks, Pietro.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Modernizr
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#