-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathimage-slidebar
42 lines (37 loc) · 1.03 KB
/
image-slidebar
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
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS for the slider */
.slider-container {
text-align: center;
margin-top: 20px;
}
#slider-image {
width: 300px;
height: 200px;
}
#slider {
width: 80%;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="slider-container">
<img id="slider-image" src="image1.jpg" alt="Image Slider">
<input type="range" id="slider" min="1" max="3" step="1" value="1">
</div>
<script>
// JavaScript for the slider
const slider = document.getElementById('slider');
const sliderImage = document.getElementById('slider-image');
slider.addEventListener('input', () => {
// Get the value of the slider
const sliderValue = parseInt(slider.value);
// Update the image source based on the slider value
sliderImage.src = `image${sliderValue}.jpg`;
});
</script>
</body>
</html>