Skip to content

Instantly share code, notes, and snippets.

@drazisil
Created March 27, 2018 13:13
Show Gist options
  • Save drazisil/7174dc58a20e5643e734ea61c30693f1 to your computer and use it in GitHub Desktop.
Save drazisil/7174dc58a20e5643e734ea61c30693f1 to your computer and use it in GitHub Desktop.
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