-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (34 loc) · 829 Bytes
/
script.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
const imgs = document.querySelectorAll('.header-slider ul img')
const prev_btn = document.querySelector('.control_prev');
const next_btn = document.querySelector('.control_next');
let n=1;
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;
});
}