-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshow.html
89 lines (85 loc) · 2.71 KB
/
slideshow.html
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
79
80
81
82
83
84
85
86
87
88
89
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div class="slideshow-container">
<div class="slide">
<img
src="https://repository-images.githubusercontent.com/260096455/47f1b200-8b2e-11ea-8fa1-ab106189aeb0"
style="width: 100%"
/>
</div>
<div class="slide">
<img
src="https://images.dog.ceo/breeds/terrier-irish/n02093991_1679.jpg"
style="width: 100%"
/>
</div>
<div class="slide">
<img
src="https://images.dog.ceo/breeds/terrier-american/n02093428_3800.jpg"
style="width: 100%"
/>
</div>
<a class="prev" onclick="moveSlide(-1)">❮</a>
<a class="next" onclick="moveSlide(1)">❯</a>
</div>
<style>
.slideshow-container {
position: relative;
max-height: 50vh;
overflow: hidden;
}
.slide {
display: none;
height: 100%;
}
.slide img {
height: 100%;
object-fit: cover;
aspect-ratio: 16 / 9;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
transform: translateY(-50%);
padding: 16px;
color: white;
font-weight: bold;
font-size: 24px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
</style>
<script>
let slideIndex = 0;
const slides = document.getElementsByClassName("slide");
showSlides(slideIndex);
function moveSlide(n) {
slideIndex = (slideIndex + n + slides.length) % slides.length;
showSlides();
}
function showSlides() {
Array.from(slides).forEach((slide) => {
slide.style.display = "none";
});
slides[slideIndex].style.display = "block";
}
</script>
</body>
</html>