forked from yell0wfl4sh/Image-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
95 lines (77 loc) · 2.13 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var displayedImage = document.querySelector('#image');
var thumbBar = document.querySelector('.thumb-bar');
opacitybtn = document.getElementById('opac');
upbtn = document.getElementById('updir');
downbtn = document.getElementById('downdir');
var overlay = document.querySelector('.display');
var images=[];
for(var i=1;i <=11;i++){
images.push('img/img'+ i+ '.jpg');
}
for(var i = 1; i <= 11; i++) {
var newImage = document.createElement('img');
newImage.setAttribute('src', 'img/img' + i + '.jpg');
thumbBar.appendChild(newImage);
newImage.onclick = function(e) {
var imgSrc = e.target.getAttribute('src');
displayImage(imgSrc);
}
}
function displayImage(imgSrc) {
displayedImage.setAttribute('src', imgSrc);
}
opacitybtn.onclick = function() {
var btnClass = opacitybtn.getAttribute('class');
if(btnClass === 'dark') {
opacitybtn.setAttribute('class','light');
opacitybtn.textContent = 'Lighten';
displayedImage.style.opacity = '0.5';
} else {
opacitybtn.setAttribute('class','dark');
opacitybtn.textContent = 'Darken';
displayedImage.style.opacity = '1';
}
}
upbtn.onclick=function(){
upimage();
}
function upimage(){
var current = displayedImage.getAttribute('src');
var index = images.indexOf(current)- 1;
if (index== -1){
displayImage(images[10]);
}
else{
displayImage(images[index]);
}
}
downbtn.onclick=function(){
downimage();
}
function downimage(){
var current = displayedImage.getAttribute('src');
var index = images.indexOf(current)+ 1;
if (index== 11){
displayImage(images[0]);
}
else{
displayImage(images[index]);
}
}
function changeImg(e){
if(e.keyCode=="38"){
upimage();
}
if(e.keyCode=="40"){
downimage();
}
}
window.addEventListener(`keydown`,changeImg);
//*********Controls**********
const inputs = document.querySelectorAll(`.controls input`);
function updateValue(){
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`,this.value+suffix);
}
inputs.forEach(input => input.addEventListener('change',updateValue));
inputs.forEach(input => input.addEventListener('mousemove',updateValue));