File tree 3 files changed +35
-7
lines changed
3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 9
9
< body >
10
10
< div class ="carousel ">
11
11
< div class ="image-container " id ="imgs ">
12
+ < img
13
+ src ="https://images.unsplash.com/photo-1599561046251-bfb9465b4c44?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1492&q=80 "
14
+ alt ="fourth-image "
15
+ />
12
16
< img src ="https://images.unsplash.com/photo-1599394022918-6c2776530abb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1458&q=80 "
13
17
alt ="first-image "
14
18
/>
24
28
src ="https://images.unsplash.com/photo-1599561046251-bfb9465b4c44?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1492&q=80 "
25
29
alt ="fourth-image "
26
30
/>
31
+ < img src ="https://images.unsplash.com/photo-1599394022918-6c2776530abb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1458&q=80 "
32
+ alt ="first-image "
33
+ />
27
34
</ div >
28
35
29
36
< div class ="buttons-container ">
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const rightBtn = document.getElementById('right')
4
4
5
5
const img = document . querySelectorAll ( '#imgs img' )
6
6
7
- let idx = 0
7
+ let idx = 1
8
8
9
9
let interval = setInterval ( run , 2000 )
10
10
@@ -15,12 +15,34 @@ function run() {
15
15
16
16
function changeImage ( ) {
17
17
if ( idx > img . length - 1 ) {
18
- idx = 0
19
- } else if ( idx < 0 ) {
20
18
idx = img . length - 1
21
- }
22
19
23
- imgs . style . transform = `translateX(${ - idx * 500 } px)`
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
+ 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)`
44
+ }
45
+
24
46
}
25
47
26
48
function resetInterval ( ) {
Original file line number Diff line number Diff line change 28
28
29
29
.image-container {
30
30
display : flex;
31
- transform : translateX (0 );
32
- transition : transform 0.5s ease-in-out;
31
+ transform : translateX (-500px );
33
32
}
34
33
35
34
.buttons-container {
You can’t perform that action at this time.
0 commit comments