Skip to content

Instantly share code, notes, and snippets.

@bytespider
Created October 25, 2011 11:44
Show Gist options
  • Save bytespider/1312426 to your computer and use it in GitHub Desktop.
Save bytespider/1312426 to your computer and use it in GitHub Desktop.
Replace images with hires versions on iPhone4+
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<style>
html, body { padding: 0; margin: 0; }
</style>
</head>
<body>
<img src="testcardk_320.jpg" data-src="testcardk_640.jpg" width="320">
<script>
if (!!window.devicePixelRatio && window.devicePixelRatio > 1)
{
var images = document.querySelectorAll("img[data-src]"),
length = images.length,
i = 0;
for (; i < length; ++i)
{
images[i].src = images[i].dataset.src;
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment