-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiment14.html
More file actions
53 lines (45 loc) · 1.24 KB
/
Experiment14.html
File metadata and controls
53 lines (45 loc) · 1.24 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
<!DOCTYPE html>
<html>
<head>
<title>Image Slider using jquery </title>
</head>
<style>
#slider { width: 300px; height: 200px;
overflow: hidden; position: relative;
}
.slide {
width: 100%;
height: 100%; display: none; position: absolute;
}
img {
width: 100%;
height: 100%;
}
button {
margin-top: 10px; padding: 10px;
}
</style>
<body>
<h3>Image Slider using jquery</h3>
<div id="slider">
<div class="slide"><img src="image1.jpg" alt="Image 1"></div>
<div class="slide"><img src="image2.jpg" alt="Image 2"></div>
<div class="slide"><img src="image3.jpg" alt="Image 3"></div>
</div>
<button id="prev"><</button>
<button id="next">></button>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () { var currentIndex = 0;
var slides = $('.slide');
// Show the first slide slides.eq(currentIndex).show();
$('#prev').on('click', function () { slides.eq(currentIndex).hide();
currentIndex = (currentIndex - 1 + slides.length) % slides.length; slides.eq(currentIndex).show();
});
$('#next').on('click', function () { slides.eq(currentIndex).hide();
currentIndex = (currentIndex + 1) % slides.length; slides.eq(currentIndex).show();
});
});
</script>
</html>