Created
December 9, 2013 09:49
-
-
Save gerbenvandijk/7869821 to your computer and use it in GitHub Desktop.
Simple retina <img>
This file contains hidden or 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
<img src="myimage.jpg" data-2x="myimage-2x.jpg"> |
This file contains hidden or 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 elems = document.getElementsByTagName('*'); | |
for(var i=0;i < elems.length;i++){ | |
var attr = elems[i].getAttribute('data-2x'); | |
if(attr && elems[i].tagName == 'IMG'){ | |
elems[i].src = attr; | |
} else if(attr){ | |
elems[i].style.cssText += 'background-image: url('+attr+')'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment