Skip to content

Instantly share code, notes, and snippets.

@KATT
Last active January 2, 2016 09:19
Show Gist options
  • Save KATT/8282106 to your computer and use it in GitHub Desktop.
Save KATT/8282106 to your computer and use it in GitHub Desktop.
<img src="images/header.png" data-srcorig="images/[email protected]">
// retinaify imgs
var isRetina = window.devicePixelRatio > 1;
if (isRetina) {
var imgs = document.getElementsByTagName('img');
for (var i = 0; i < imgs.length; i++) {
var img = imgs[i];
var src2x = img.dataset && img.dataset.src2x;
if (src2x) {
img.setAttribute('data-src-orig', img.src);
img.src = src2x;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment