Created
July 6, 2012 17:43
-
-
Save pixelrevision/3061572 to your computer and use it in GitHub Desktop.
Simple js retina image 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
$(document).ready(function(){ | |
var dpr = 1; | |
if(window.devicePixelRatio !== undefined) dpr = window.devicePixelRatio; | |
if(dpr >= 2){ | |
// convert image links to @2x images | |
$("img").each(function(){ | |
var newSrc = $(this).attr("src").replace(".png", "@2x.png"); | |
newSrc = $(this).attr("src").replace(".jpg", "@2x.jpg"); | |
newSrc = $(this).attr("src").replace(".jpeg", "@2x.jpeg"); | |
$(this).attr("src", newSrc); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment