Skip to content

Commit b1e2d47

Browse files
authored
Update script.js
1 parent 0561e5e commit b1e2d47

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

image-carousel/script.js

+6-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const rightBtn = document.getElementById('right')
44

55
const img = document.querySelectorAll('#imgs img')
66

7-
let idx = 1
7+
let idx = 0
88

99
let interval = setInterval(run, 2000)
1010

@@ -15,34 +15,12 @@ function run() {
1515

1616
function changeImage() {
1717
if(idx > img.length - 1) {
18-
idx = img.length - 1
19-
20-
imgs.style.transition = 'all, linear, 1s';
21-
imgs.style.transform = `translateX(${-idx * 500}px)`
22-
23-
setTimeout(function() {
24-
idx = 1;
25-
imgs.style.transition = '';
26-
imgs.style.transform = `translateX(${-500}px)`
27-
},0)
28-
}
29-
else if(idx < 0){
3018
idx = 0
31-
32-
imgs.style.transition = 'all, linear, 1s';
33-
imgs.style.transform = `translateX(${-idx * 500}px)`
34-
35-
setTimeout(function() {
36-
idx = img.length - 2;
37-
imgs.style.transition = '';
38-
imgs.style.transform = `translateX(${-idx * 500}px)`
39-
},0)
40-
}
41-
else{
42-
imgs.style.transition = 'all, linear, 1s';
43-
imgs.style.transform = `translateX(${-idx * 500}px)`
19+
} else if(idx < 0) {
20+
idx = img.length - 1
4421
}
45-
22+
23+
imgs.style.transform = `translateX(${-idx * 500}px)`
4624
}
4725

4826
function resetInterval() {
@@ -60,4 +38,4 @@ leftBtn.addEventListener('click', () => {
6038
idx--
6139
changeImage()
6240
resetInterval()
63-
})
41+
})

0 commit comments

Comments
 (0)