-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path新闻卡片 copy 4.html
79 lines (73 loc) · 1.86 KB
/
新闻卡片 copy 4.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
<!DOCTYPE html>
<html>
<head>
<title>Image Carousel</title>
<style>
#carousel {
width: 500px;
height: 300px;
overflow: hidden;
position: relative;
}
#carousel img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
transition: opacity 0.5s ease-in-out;
}
#carousel button {
position: absolute;
top: 50%;
transform: translateY(-50%);
background-color: transparent;
border: none;
color: white;
font-size: 2rem;
cursor: pointer;
}
#carousel button.previous {
left: 0;
}
#carousel button.next {
right: 0;
}
</style>
</head>
<body>
<div id="carousel">
<img id="image" src="" alt="">
<button class="previous" onclick="previousImage()">❮</button>
<button class="next" onclick="nextImage()">❯</button>
</div>
<script>
const images = ["https://p3.itc.cn/q_70/images03/20201103/888aea5ec34e4cf3982373e9b7babe3d.jpeg", "path/to/image2.jpg", "path/to/image3.jpg"];
let index = 0;
const imageElement = document.getElementById("image");
function showImage() {
imageElement.src = images[index];
}
function previousImage() {
index--;
if (index < 0) {
index = images.length - 1;
}
imageElement.style.opacity = 0;
setTimeout(() => {
showImage();
imageElement.style.opacity = 1;
}, 500);
}
function nextImage() {
index++;
if (index >= images.length) {
index = 0;
}
imageElement.style.opacity = 0;
setTimeout(() => {
showImage();
imageElement.style.opacity = 1;
}, 500);
}