Created
August 21, 2014 09:23
-
-
Save abovedave/ea846f79a2b139676bc9 to your computer and use it in GitHub Desktop.
Retina images replacement
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
if(window.devicePixelRatio >= 1.2){ | |
var images = document.getElementsByTagName('img'); | |
for(var i=0;i < images.length;i++){ | |
var attr_2x = images[i].getAttribute('data-2x'); | |
if(attr_2x){ | |
images[i].src = attr_2x; | |
} | |
} | |
} else { | |
var images = document.getElementsByTagName('img'); | |
for(var i=0;i < images.length;i++){ | |
var attr_1x = images[i].getAttribute('data-1x'); | |
if(attr_1x){ | |
images[i].src = attr_1x; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment