I have successfully created an image carousel.
https://i.sstatic.net/CbypXxRr.png
Encountered Challenges:
The last slide is displayed, but the counter shows the first slide. How can I resolve this issue?
When clicking play, it continues to advance the count. Is there a way to make it stop at the last slide?
Upon clicking "last", the "next" and "last" buttons are greyed out. Similarly, clicking "first" greys-out the "prev" and "first" buttons. CSS was used for this styling. How can I automate this behavior using jQuery?
Attempts Made:
I attempted adding the class .active to the last image and hiding the others with css. However, the counter still displays 1/6 instead of 6/6.
I tried implementing a function that checks if the current slide is the last one. Unfortunately, it did not work as expected:
function lastSlide() {
if ($('.image').last().hasClass('active')){
clearTimeout(slideTimer);
} else {
slideImage(0);
};
};
var totalImages = $('.images').length;
sliderCompleted: function(current) {
if (slideImage >= totalImages) {
clearTimeout(slideTimer);
};
- I believe I need to use
$('.images:last')
, but am struggling with how to incorporate this.
I am hopeful someone can guide me in the correct direction...
The HTML CSS & jQuery: