0% found this document useful (0 votes)
8 views

css16

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

css16

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

<html>

<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>

You might also like