File tree Expand file tree Collapse file tree 3 files changed +36
-5
lines changed
projects/testimonial-slider Expand file tree Collapse file tree 3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 9
9
head >
10
10
< body >
11
11
< div class ="testimonial-container ">
12
+ < button class ="arrow prev " onclick ="prevTestimonial() "> ❮button >
12
13
< img
13
14
src ="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=880&q=80 "
14
15
alt ="user-image "
18
19
best. Not able to tell you how happy I am with Apple.
19
20
p >
20
21
< h4 class ="username "> Cherise Gh4 >
22
+ < button class ="arrow next " onclick ="nextTestimonial() "> ❯button >
21
23
div >
22
24
< script src ="index.js "> script >
23
25
body >
Original file line number Diff line number Diff line change @@ -32,11 +32,20 @@ function updateTestimonial() {
32
32
imgEl . src = photoUrl ;
33
33
textEl . innerText = text ;
34
34
usernameEl . innerText = name ;
35
+ }
36
+
37
+ function nextTestimonial ( ) {
35
38
idx ++ ;
36
- if ( idx == = testimonials . length ) {
39
+ if ( idx > = testimonials . length ) {
37
40
idx = 0 ;
38
41
}
39
- setTimeout ( ( ) => {
40
- updateTestimonial ( ) ;
41
- } , 10000 ) ;
42
+ updateTestimonial ( ) ;
43
+ }
44
+
45
+ function prevTestimonial ( ) {
46
+ idx -- ;
47
+ if ( idx < 0 ) {
48
+ idx = testimonials . length - 1 ;
49
+ }
50
+ updateTestimonial ( ) ;
42
51
}
Original file line number Diff line number Diff line change 8
8
}
9
9
10
10
.testimonial-container {
11
+ position : relative;
11
12
width : 500px ;
12
13
height : 100px ;
13
14
background-color : slateblue;
17
18
padding : 70px 20px ;
18
19
margin : 5px ;
19
20
color : white;
20
- position : relative;
21
21
}
22
22
23
23
img {
34
34
font-size : 13px ;
35
35
font-weight : 100 ;
36
36
}
37
+
38
+ .arrow {
39
+ position : absolute;
40
+ top : 50% ;
41
+ transform : translateY (-50% );
42
+ background : none;
43
+ border : none;
44
+ color : white;
45
+ font-size : 24px ;
46
+ cursor : pointer;
47
+ margin : 70px ;
48
+ }
49
+
50
+ .arrow .prev {
51
+ left : 10px ;
52
+ }
53
+
54
+ .arrow .next {
55
+ right : 10px ;
56
+ }
You can’t perform that action at this time.
0 commit comments