Skip to content

Instantly share code, notes, and snippets.

@rc1
Created March 23, 2012 16:54
Show Gist options
  • Select an option

  • Save rc1/2172730 to your computer and use it in GitHub Desktop.

Select an option

Save rc1/2172730 to your computer and use it in GitHub Desktop.
Retina Display Image Sources
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script>
$(function () {
$("img[data-lowres]").each(function (index, el) {
$(el).attr({src: (window.devicePixelRatio) ? $(el).data("highres") : $(el).data("lowres") });
});
});
</script>
</head>
<body>
<img data-lowres="img.gif" data-highres="img_highres.gif" src="transparent.gif" />
<noscript>
<img src="img.gif" />
</noscript>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment