-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (34 loc) · 905 Bytes
/
script.js
File metadata and controls
40 lines (34 loc) · 905 Bytes
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
const imgs = document.querySelectorAll('.header-slider ul img');
const prev_btn = document.querySelector('.control_prev');
const next_btn = document.querySelector('.control_next');
let n = 0;
function changeSlide(){
for(let i = 0; i < imgs.length; i++){
imgs[i].style.display = 'none';
}
imgs[n].style.display = 'block';
}
changeSlide();
prev_btn.addEventListener('click', (e) => {
if(n > 0){
n--;
}else{
n = imgs.length - 1;
}
changeSlide();
})
next_btn.addEventListener('click', (e) => {
if(n < imgs.length- 1){
n++;
}else{
n = 0;
}
changeSlide();
})
const scrollContainer = document.querySelectorAll('.products');
for (const item of scrollContainer){
item.addEventListener('wheel', (evt) => {
evt.preventDefault();
item.scrollLeft +=evt.deltaY;
})
}