css16
css16
<head>
<title>Simple Image Slideshow</title>
</head>
<body>
<img id="slide" src="lion.jpg" alt="Slideshow Image" width="400"
height="300">
<script>
const images = ["lion.jpg", "tiger.jpg", "panther.jpg"];
let currentIndex = 0;
function showNextImage() {
currentIndex = (currentIndex + 1) % images.length;
document.getElementById('slide').src = images[currentIndex];
}
setInterval(showNextImage, 3000);
</script>
</body>
</html>
1. 2.
3.
<html>
<head>
<title>Simple Image Slideshow with Buttons</title>
</head>
<body>
<img id="slide" src="lion.jpg" alt="Slideshow Image" width="400"
height="300">
<br> <br>
<button onclick="showPreviousImage()">Previous</button>
<button onclick="showNextImage()">Next</button>
<script>
const images = ["lion.jpg", "tiger.jpg", "panther.jpg"];
let currentIndex = 0;
function showNextImage() {
currentIndex = (currentIndex + 1) % images.length;
document.getElementById('slide').src = images[currentIndex];
}
function showPreviousImage() {
currentIndex = (currentIndex - 1 + images.length) % images.length;
document.getElementById('slide').src = images[currentIndex];
}
</script>
</body>
</html>