-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_program_09.html
More file actions
78 lines (74 loc) · 2.07 KB
/
js_program_09.html
File metadata and controls
78 lines (74 loc) · 2.07 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!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 {
text-align: center;
position: relative;
width: 60%;
margin: auto;
}
.slider img {
width: 100%;
height: auto;
}
.slider button {
position: absolute;
top: 50%;
transform: translateY(-50%);
padding: 10px;
background-color: rgba(0, 0, 0, 0.5);
color: white;
border: none;
cursor: pointer;
}
#prevBtn {
left: 10px;
}
#nextBtn {
right: 10px;
}
</style>
</head>
<body>
<div class="slider">
<img src="https://tse2.mm.bing.net/th/id/OIP.NrLB6OSIOBQw45qWOptd-AHaDL?rs=1&pid=ImgDetMain&o=7&rm=3" class="slider-image" alt="Image 1">
<button id="prevBtn">Previous</button>
<button id="nextBtn">Next</button>
</div>
<script>
// Array of image URLs
const images = [
"https://tse2.mm.bing.net/th/id/OIP.NrLB6OSIOBQw45qWOptd-AHaDL?rs=1&pid=ImgDetMain&o=7&rm=3",
"https://wallpaperaccess.com/full/6163606.jpg",
"https://wallpaperaccess.com/full/9411696.jpg",
"https://images.hdqwalls.com/download/2020-pubg-game-season-4k-g5-1920x1080.jpg"
];
let currentIndex = 0;
const imgElement = document.querySelector(".slider-image");
const nextBtn = document.getElementById("nextBtn");
const prevBtn = document.getElementById("prevBtn");
// Update image function
function showImage(index) {
imgElement.src = images[index];
}
// Manual image navigation
nextBtn.addEventListener("click", () => {
currentIndex = (currentIndex + 1) % images.length;
showImage(currentIndex);
});
prevBtn.addEventListener("click", () => {
currentIndex = (currentIndex - 1 + images.length) % images.length;
showImage(currentIndex);
});
// Optional: Automatic image change every 3 seconds
setInterval(() => {
currentIndex = (currentIndex + 1) % images.length;
showImage(currentIndex);
}, 3000);
</script>
</body>
</html>