Skip to content

Instantly share code, notes, and snippets.

@robspangler
Last active August 29, 2015 13:57
Show Gist options
  • Save robspangler/9505054 to your computer and use it in GitHub Desktop.
Save robspangler/9505054 to your computer and use it in GitHub Desktop.
CSS and JavaScript needed to accommodate Retina devices
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
}
if (window.devicePixelRatio == 2) {
var images = $("img.2x");
// loop through the images and make them hi-res
for(var i = 0; i < images.length; i++) {
// create new image name
var imageType = images[i].src.substr(-4);
var imageName = images[i].src.substr(0, images[i].src.length - 4);
imageName += "@2x" + imageType;
//rename image
images[i].src = imageName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment