Created
March 27, 2018 13:13
-
-
Save drazisil/7174dc58a20e5643e734ea61c30693f1 to your computer and use it in GitHub Desktop.
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
const opacity = 0.4; | |
const current = document.querySelector("#current"); | |
const [maxHeight, maxWidth] = [current.height, current.width]; | |
const imgs = document.querySelectorAll(".imgs img"); | |
imgs[0].style.opacity = opacity; | |
function imgClick(e) { | |
// reset opacity for all images | |
imgs.forEach(img => { | |
img.style.opacity = 1; | |
}); | |
const newImg = e.target; | |
current.src = newImg.src; | |
current.height = maxHeight; | |
current.width = maxWidth; | |
current.classList.add("fade-in"); | |
setTimeout(() => { | |
current.classList.remove("fade-in"); | |
}, 500); | |
e.target.style.opacity = opacity; | |
} | |
imgs.forEach(img => img.addEventListener("click", imgClick)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment