I made this image slider up to this level and I think I need some help.
I created an image slider with arrows, and thumbnails at the bottom of the display slider. The display slider works just fine, only that from the JavaScript code I've written, I can't seem to make each thumbnail correspond with the display image slider.
My intention for this slider to work was that: when a thumbnail is clicked, it would reflect in the display slider. Also, when the left or right arrow of the display slider is clicked, the corresponding thumbnail becomes active. And finally, with a fade transitioning, maybe?
See the code I wrote:
let leftArrow = document.querySelector('#slide_left')
let rightArrow = document.querySelector('#slide_right')
let slidesContainer = document.querySelector('#slides')
leftArrow.addEventListener('click', function() {
const last = document.querySelector('#slides > :last-child');
last.remove();
slidesContainer.prepend(last);
})
rightArrow.addEventListener('click', function() {
const first = document.querySelector('#slides > :first-child');
first.remove();
slidesContainer.append(first);
})
* {
box-sizing: border-box;
}
body {
background-color: #555;
height: 100vh;
display: grid;
align-items: center;
justify-items: center;
}
div#slides_wrapper {
width: 400px;
display: flex;
border: 2px solid #efefef;
justify-content: space-between;
margin-bottom: 20px;
}
div#slides_wrapper div#slides {
width: 300px;
overflow: hidden;
display: flex;
background-color: #0ff3;
}
img.slide {
width: 100%;
}
img.thumbnail {
width: 50px;
}
div.slide_arrow {
font-size: 20px;
background-color: #0f0f0f;
color: #f0f0f0;
height: 40px;
width: 40px;
display: grid;
justify-items: center;
align-items: center;
align-self: center;
}
div.slide_arrow:hover {
cursor: pointer;
}
div.slide_arrow#slide_left {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
div.slide_arrow#slide_right {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
div#thumbnails {
width: 400px;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
div#thumbnails img.thumbnail {
background-color: #888;
margin: 5px;
}
div#thumbnails img.thumbnail:hover {
cursor: pointer;
}
div#thumbnails img.thumbnail.active {
border: 2px solid #0ff;
}
<div id="main_wrapper">
<div id="slides_wrapper">
<div id="slide_left" class="slide_arrow"><span>❮</span></div>
<div id="slides">
<img class="slide" src="https://images.pexels.com/photos/1564149/pexels-photo-1564149.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="slide" src="https://images.pexels.com/photos/783243/pexels-photo-783243.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="slide" src="https://images.pexels.com/photos/4066293/pexels-photo-4066293.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="slide" src="https://images.pexels.com/photos/428340/pexels-photo-428340.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="slide" src="https://images.pexels.com/photos/9558760/pexels-photo-9558760.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="slide" src="https://images.pexels.com/photos/5701644/pexels-photo-5701644.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
</div>
<div id="slide_right" class="slide_arrow"><span>❯</span></div>
</div>
<div id="thumbnails">
<img class="thumbnail active" src="https://images.pexels.com/photos/1564149/pexels-photo-1564149.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="thumbnail" src="https://images.pexels.com/photos/783243/pexels-photo-783243.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="thumbnail" src="https://images.pexels.com/photos/4066293/pexels-photo-4066293.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="thumbnail" src="https://images.pexels.com/photos/428340/pexels-photo-428340.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="thumbnail" src="https://images.pexels.com/photos/9558760/pexels-photo-9558760.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
<img class="thumbnail" src="https://images.pexels.com/photos/5701644/pexels-photo-5701644.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="" />
</div>
</div>
Please feel free to alter the code, if need be. I really need help.