Created
February 15, 2013 17:14
-
-
Save aqualungdesign/4961820 to your computer and use it in GitHub Desktop.
função para alterar as imagens do html por retina display.
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
// Funcao para alterar o src das imagens caso o usuario | |
// esteja utilizando um dispositivo com retina display | |
var retina = function(imgFolder, retinaFolder){ | |
if (window.devicePixelRatio === 2) { | |
var $retinaImages = $("img.hires"); | |
for(var i = 0; i < $retinaImages.length; i++){ | |
var $imageType = $retinaImages[i].src.substr(-4); | |
var $imageName = $retinaImages[i].src.substr(0, $retinaImages[i].src.length - 4); | |
$imageName += "@2x" + $imageType; | |
// testa a mudanca de diretorio da imagem | |
if(imgFolder || retinaFolder == true){ | |
$retinaImages[i].src = $imageName.replace(imgFolder, retinaFolder); | |
} | |
else{ | |
$retinaImages[i].src = $imageName; | |
}; | |
}; | |
}; | |
}; | |
$(function(){ | |
// se a funcao for chamada sem nenhum diretorio o js usa o diretorio raiz. | |
retina("/img/", "/img/retina/"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment