-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
58 lines (49 loc) · 1.74 KB
/
main.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var displayedImage = document.querySelector('.displayed-img');
var thumbBar = document.querySelector('.thumb-bar');
var darkenbtn = document.querySelector('#darken');
var hidebtn = document.querySelector('#hide')
var overlay = document.querySelector('.overlay');
/* Looping through images */
for(i=1;i<6;i++){
// var xxx = "\images\pic"+i+".jpg";
var newImage = document.createElement('img');
newImage.setAttribute('src', "images/pic"+i+".jpg");
thumbBar.appendChild(newImage);
newImage.onclick = function(e) {
var newPic = e.target.getAttribute('src');
picClick(newPic);
}
}
function picClick(newPic) {
displayedImage.setAttribute('src', newPic);
}
/* Wiring up the Darken/Lighten button */
darkenbtn.onclick = function () {
// console.log('darken button clicked');
let btnClass = darkenbtn.getAttribute('class');
if(btnClass === "dark"){
darkenbtn.setAttribute('class', "light");
overlay.style.backgroundColor = "rgba(0,0,0,0.5)";
darkenbtn.textContent = "Lighten";
} else if (btnClass = "light"){
darkenbtn.setAttribute('class', "dark");
overlay.style.backgroundColor = "rgba(0,0,0,0)";
darkenbtn.textContent = "Darken";
}
}
/* Hide everything */
hidebtn.onclick = function () {
// console.log('hide button clicked');
let btnClass = hidebtn.getAttribute('class');
if(btnClass === 'hide'){
hidebtn.setAttribute('class', 'unhide');
hidebtn.textContent = "Unhide";
displayedImage.setAttribute('class','toggle-hide');
thumbBar.setAttribute('class','toggle-hide');
} else if (btnClass = 'unhide'){
hidebtn.setAttribute('class', 'hide');
hidebtn.textContent = "Hide";
displayedImage.setAttribute('class','full-img');
thumbBar.setAttribute('class','thumb-bar');
}
}