Created
December 24, 2012 15:18
-
-
Save toddmotto/4369618 to your computer and use it in GitHub Desktop.
Progressive enhancement technique for HTML5, retina detection to optimise your CSS. Usage in CSS:
.no-retina { /* styles */ }
.retina { /* styles */ }
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retina Device, add 'retina' to HTML tag | |
if (window.devicePixelRatio >= 2) { | |
document.getElementsByTagName('html')[0].className += ' retina'; | |
} | |
// No-retina Device, add 'no-retina' to HTML tag | |
else { | |
document.getElementsByTagName('html')[0].className += ' no-retina'; | |
} |
You could even just over-ride it if it's the only (or first) class addition.
if (window.devicePixelRatio >= 2) {
document.documentElement.className = ' retina';
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be faster if you had "no-retina" on the html tag by default then did this:
I use this pattern for js detection/progressive enhancement