Created
July 10, 2018 01:00
-
-
Save guibranco/b2104ab5a0d333a3825312ee77e1643d to your computer and use it in GitHub Desktop.
Função para substituir imagem e adicionar transição CSS - Facebook - HTML5 e CSS3 - https://www.facebook.com/groups/361826063881448/permalink/1902228279841211/
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
function changeImage(id, newImagePath, transitionClass){ | |
var myImage = document.getElementById(id); | |
var image = new Image(); | |
image.addEventListener("load", function() { | |
myImage.className = transitionClass; | |
}); | |
image.src = newImagePath; | |
image.id = id; | |
myImage.replaceWith(image); | |
} | |
//para chamar só usar: | |
//changeImage("id_da_tag_da_imagem","/pasta/imagens/imagem2.jpg", "classe_css_com_transição"); | |
//lembre-se de criar a transição CSS com o nome da clase passado como terceiro argumento. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment