Last active
December 25, 2015 08:19
-
-
Save Kaiyuan/6945613 to your computer and use it in GitHub Desktop.
Easy Retina Picture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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