-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path9.html
More file actions
50 lines (45 loc) · 1.4 KB
/
Copy path9.html
File metadata and controls
50 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Slider</title>
<style>
#slider {
max-width: 300px;
margin: 0 auto;
overflow: hidden;
}
#image {
width: 100%;
transition: transform 0.5s ease;
}
</style>
</head>
<body>
<h1>Image Slider</h1>
<div id="slider">
<img id="image" src="sampleimg.jpg" alt="Image 1">
</div>
<button id="prevButton">Previous</button>
<button id="nextButton">Next</button>
<script>
const image = document.getElementById("image");
const prevButton = document.getElementById("prevButton");
const nextButton = document.getElementById("nextButton");
const images = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg"];
let currentIndex = 0;
prevButton.addEventListener("click", function() {
currentIndex = (currentIndex - 1 + images.length) % images.length;
updateImage();
});
nextButton.addEventListener("click", function() {
currentIndex = (currentIndex + 1) % images.length;
updateImage();
});
function updateImage() {
image.style.transform = `translateX(-${currentIndex * 100}%)`;
}
</script>
</body>
</html>