object
| -
Hi guys,
this is my code and it’s currently working. What do you
think?
/* Looping through images */
for (i = 1; i <= 5; i++) {
var newImage = document.createElement(‘img’);
newImage.setAttribute(‘src’, ‘./images/pic’ + i +
‘.jpg’);
thumbBar.appendChild(newImage);
newImage.onclick = getTheImage;
function getTheImage(e, src) {
var src = e.target.getAttribute(‘src’);
displayedImage.setAttribute(‘src’, src);
};
};
/* Wiring up the Darken/Lighten button */
btn.onclick = changeOverlay;
function changeOverlay () {
var cl = btn.getAttribute(‘class’);
if (cl === ‘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)’;
}
};
|