Skip to content

Instantly share code, notes, and snippets.

@pixelrevision
Created July 6, 2012 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelrevision/3061572 to your computer and use it in GitHub Desktop.
Save pixelrevision/3061572 to your computer and use it in GitHub Desktop.
Simple js retina image replacement
$(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