Skip to content

Instantly share code, notes, and snippets.

@cristianferrarig
Last active December 15, 2015 05:59
Show Gist options
  • Save cristianferrarig/5212996 to your computer and use it in GitHub Desktop.
Save cristianferrarig/5212996 to your computer and use it in GitHub Desktop.
Add class "retina" in HTML tag for high pixel ratio devices
// jQuery mode
if (window.devicePixelRatio > 1) {
$('body').addClass('retina');
}
// Only javascript mode
if (window.devicePixelRatio > 1) {
var elHtml = document.getElementsByTagName('html')[0];
var atrClass = elHtml.getAttribute('class');
atrClass = atrClass + ' retina';
elHtml.setAttribute('class', atrClass); //For Most Browsers
//elHtml.setAttribute('className', atrClass); //For IE; harmless to other brow
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment