Skip to content

Instantly share code, notes, and snippets.

@joaocunha
Created November 27, 2013 13:46
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joaocunha/7675924 to your computer and use it in GitHub Desktop.
Modernizr test for retina / high resolution / high pixel density.
/**
* 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);
});
@joaocunha
Copy link
Author

Side note: the test takes ~0.35ms to run on my device.

@wiesys
Copy link

wiesys commented Mar 9, 2015

Great idea – thanks! 😄

Just a curiosity – Why do you use return !!(dpr > 1); instead of just return dpr > 1;? Are there any benefits?

@mishterk
Copy link

I'm also curious as to you use return !!(dpr > 1) instead of just return dpr > 1...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment