-
-
Save gchib00/db1e8f98a689dd833b9c5545f1e3fd7e 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 displayedImage = document.querySelector('.displayed-img'); | |
const thumbBar = document.querySelector('.thumb-bar'); | |
const btn = document.querySelector('button'); | |
const overlay = document.querySelector('.overlay'); | |
/* Looping through images */ | |
for (let i=1; i<=5; i++){ | |
const newImage = document.createElement('img'); | |
newImage.setAttribute('src', "pic"+i+".jpg"); | |
thumbBar.appendChild(newImage); | |
newImage.addEventListener("click", function(){ | |
document.getElementById("mainImage").src = "pic"+i+".jpg"; | |
}); | |
} | |
/* Wiring up the Darken/Lighten button */ | |
btn.addEventListener("click", function(){ | |
const btnClass = btn.getAttribute('class'); | |
if(btnClass === 'dark') { | |
btn.setAttribute('class','light'); | |
btn.textContent = 'Lighten'; | |
overlay.style.backgroundColor = 'rgba(0,0,0,0.5)'; | |
} else { | |
btn.setAttribute('class','dark'); | |
btn.textContent = 'Darken'; | |
overlay.style.backgroundColor = 'rgba(0,0,0,0)'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment