Skip to content

Instantly share code, notes, and snippets.

@Kaiyuan
Last active December 25, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kaiyuan/6945613 to your computer and use it in GitHub Desktop.
Save Kaiyuan/6945613 to your computer and use it in GitHub Desktop.
Easy Retina Picture
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Easy Retina Picture</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
jQuery(document).ready(function($) {
function retinaImg (ajaxBox) {
if (ajaxBox) {
var Img = $(ajaxBox+' img');
} else{
var Img = $('img');
};
if (window.devicePixelRatio && window.devicePixelRatio > 1) {
Img.attr('',function () {
var retina = $(this).data('retina');
var imgSrc = $(this).attr('src');
if (retina && imgSrc != retina) {
$(this).attr("src",retina);
};
});
};
};
retinaImg();
});
</script>
</head>
<body>
<a href="http://www.flickr.com/photos/d3sign/9432707789/in/faves-sealour/">
<img src="http://farm4.staticflickr.com/3708/9432707789_d944308617.jpg" data-retina="http://farm4.staticflickr.com/3708/9432707789_d944308617_b.jpg" alt="Easy Retina Pic" width="500">
</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment