Last active
November 26, 2016 05:34
-
-
Save arcreative/5145638 to your computer and use it in GitHub Desktop.
Simple retina src replacement
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
//Note: this example assumes jQuery is available on your site. | |
Retina = function() { | |
return { | |
init: function(){ | |
//Get pixel ratio and perform retina replacement | |
//Optionally, you may also check a cookie to see if the user has opted out of (or in to) retina support | |
var pixelRatio = !!window.devicePixelRatio ? window.devicePixelRatio : 1; | |
if (pixelRatio > 1) { | |
$("img").each(function(idx, el){ | |
el = $(el); | |
if (el.attr("data-src2x")) { | |
el.attr("data-src-orig", el.attr("src")); | |
el.attr("src", el.attr("data-src2x")); | |
} | |
}); | |
} | |
} | |
}; | |
}(); | |
//Init | |
Retina.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment