@@ -4,7 +4,7 @@ const rightBtn = document.getElementById('right')
4
4
5
5
const img = document . querySelectorAll ( '#imgs img' )
6
6
7
- let idx = 1
7
+ let idx = 0
8
8
9
9
let interval = setInterval ( run , 2000 )
10
10
@@ -15,34 +15,12 @@ function run() {
15
15
16
16
function changeImage ( ) {
17
17
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 ) {
30
18
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
44
21
}
45
-
22
+
23
+ imgs . style . transform = `translateX(${ - idx * 500 } px)`
46
24
}
47
25
48
26
function resetInterval ( ) {
@@ -60,4 +38,4 @@ leftBtn.addEventListener('click', () => {
60
38
idx --
61
39
changeImage ( )
62
40
resetInterval ( )
63
- } )
41
+ } )
0 commit comments