Created
March 28, 2018 14:36
-
-
Save lionhurt/6b1c3a39fbec8c245ca3fd84de949fc6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function($) { | |
if (isRetina) { //check if current device is retina | |
$('img[data-hidpi]').each(function() { // loop through images with data-hidpi attribute | |
$(this).attr('src', $(this).attr('data-hidpi')); //replace src attribute value with big image | |
}); | |
} | |
})(jQuery); | |
function isRetina(){ | |
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio >= 2)) && /(iPad|iPhone|iPod)/g.test(navigator.userAgent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment