Skip to content

Commit 513bc0e

Browse files
committed
adding an arrow in testimonial slider
1 parent 62b71ea commit 513bc0e

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

projects/testimonial-slider/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
head>
1010
<body>
1111
<div class="testimonial-container">
12+
<button class="arrow prev" onclick="prevTestimonial()">button>
1213
<img
1314
src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=880&q=80"
1415
alt="user-image"
@@ -18,6 +19,7 @@
1819
best. Not able to tell you how happy I am with Apple.
1920
p>
2021
<h4 class="username">Cherise Gh4>
22+
<button class="arrow next" onclick="nextTestimonial()">button>
2123
div>
2224
<script src="index.js">script>
2325
body>

projects/testimonial-slider/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ function updateTestimonial() {
3232
imgEl.src = photoUrl;
3333
textEl.innerText = text;
3434
usernameEl.innerText = name;
35+
}
36+
37+
function nextTestimonial() {
3538
idx++;
36-
if (idx === testimonials.length) {
39+
if (idx >= testimonials.length) {
3740
idx = 0;
3841
}
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();
4251
}

projects/testimonial-slider/style.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ body {
88
}
99

1010
.testimonial-container {
11+
position: relative;
1112
width: 500px;
1213
height: 100px;
1314
background-color: slateblue;
@@ -17,7 +18,6 @@ body {
1718
padding: 70px 20px;
1819
margin: 5px;
1920
color: white;
20-
position: relative;
2121
}
2222

2323
img {
@@ -34,3 +34,23 @@ img {
3434
font-size: 13px;
3535
font-weight: 100;
3636
}
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+
}

0 commit comments

Comments
 (0)