-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
97 lines (86 loc) · 2.35 KB
/
index.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
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<title>Animated Image Scroller</title>
<style>
#scroller {
width: 600px;
height: 300px;
position: relative;
overflow: hidden;
display: flex;
}
#image-list {
display: flex;
flex-direction: row;
animation: scroll 10s infinite linear;
}
#image-list li {
width: 200px;
height: 300px;
list-style: none;
}
#image-list img {
width: 100%;
height: 100%;
object-fit: contain;
}
@keyframes scroll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-200px);
}
}
#nav-controls {
position: absolute;
bottom: 0;
left: 0;
}
#nav-controls button {
margin: 5px;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #efefef;
cursor: pointer;
}
</style>
</head>
<body>
<div id="scroller">
<ul id="image-list">
<li><img src="image1.jpg" alt="Image 1"></li>
<li><img src="image2.jpg" alt="Image 2"></li>
<li><img src="image3.jpg" alt="Image 3"></li>
<li><img src="image4.jpg" alt="Image 4"></li>
<li><img src="image5.jpg" alt="Image 5"></li>
</ul>
</div>
<div id="nav-controls">
<button id="prev-btn">Prev</button>
<button id="next-btn">Next</button>
</div>
<script>
// Get the scroller and navigation elements
const scroller = document.getElementById('scroller');
const imageList = document.getElementById('image-list');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
// Add event listeners for navigation buttons
prevBtn.addEventListener('click', () => {
imageList.style.animationPlayState = 'paused';
const firstItem = imageList.firstElementChild;
imageList.appendChild(firstItem);
imageList.style.animationPlayState = 'running';
});
nextBtn.addEventListener('click', () => {
imageList.style.animationPlayState = 'paused';
const lastItem = imageList.lastElementChild;
imageList.insertBefore(lastItem, imageList.firstChild);
imageList.style.animationPlayState = 'running';
});
</script>
</body>
</html>