Skip to content

Instantly share code, notes, and snippets.

@dillonhafer
Created June 27, 2014 20:31
Show Gist options
  • Save dillonhafer/efca3fcf3fe895a093fc to your computer and use it in GitHub Desktop.
Save dillonhafer/efca3fcf3fe895a093fc to your computer and use it in GitHub Desktop.
var Retina = Retina || {};
Retina = {
init: function() {
var images = document.querySelectorAll("img[data-1x]");
var attr = Retina.isRetina() ? "data-2x" : "data-1x";
Array.prototype.forEach.call(images, function(el, i) {
var src = el.getAttribute(attr);
el.setAttribute("src", src);
});
},
isRetina: function() {
return window.devicePixelRatio == 2;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment