1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| const displayedImage = document.querySelector('.displayed-img'); const thumbBar = document.querySelector('.thumb-bar');
const btn = document.querySelector('button'); const overlay = document.querySelector('.overlay');
for(let i = 1; i <= 5; i++){ const newImage = document.createElement('img'); newImage.setAttribute('src', `images/pic${i}.jpg`); newImage.onclick = ()=>{displayedImage.setAttribute('src',newImage.src);}; thumbBar.appendChild(newImage); }
function updateColor(){ if(btn.getAttribute('class')==='dark'){ btn.setAttribute('class','light'); btn.textContent = 'Lighten'; overlay.style.backgroundColor = `rgba(0,0,0,0.5)`; } else{ btn.setAttribute('class','dark'); btn.textContent = 'dark'; overlay.style.backgroundColor = `rgba(0,0,0,0)`; } } btn.onclick = updateColor;
|