.slideshow-container {
position: relative;
max-width: 800px;
margin: auto;
}
.slide {
display: none;
}
.slide img {
width: 100%;
}
.prev, .next {
position: absolute;
top: 50%;
transform: translateY(-50%);
font-size: 2em;
font-weight: bold;
color: #fff;
background-color: rgba(0, 0, 0, 0.3);
padding: 1em;
cursor: pointer;
}
.prev {
left: 0;
}
.next {
right: 0;
}
var slideIndex = 0;
showSlides();
function showSlides() {
var slides = document.getElementsByClassName("slide");
for (var i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 3000); // Change image every 3 seconds
}
// Previous and next buttons
document.querySelector(".prev").addEventListener("click", function() {
slideIndex--;
if (slideIndex < 1) {
slideIndex = slides.length;
}
showSlides();
});
document.querySelector(".next").addEventListener("click", function() {
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
showSlides();
});
No comments:
Post a Comment