-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
173 lines (146 loc) · 3.46 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CodePen - Full-Screen Responsive Image Slider</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css'>
<link rel="stylesheet" href="./style.css">
<style>
@import url("https://fonts.googleapis.com/css2?family=Lexend:wght@400;700&display=swap");
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Lexend", sans-serif;
background-color: #362a2b;
color: #e5ebf3;
}
.slider {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.slide {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity 0.4s ease-in-out;
}
.slide.current {
opacity: 1;
}
.slide:first-child {
background: url("8421.jpg") no-repeat
center top/cover;
}
.slide:nth-child(2) {
background: url("5149.jpg") no-repeat
center top/cover;
}
.slide:nth-child(3) {
background: url("9844.jpg") no-repeat
center top/cover;
}
.buttons button#prev {
position: absolute;
top: 50%;
left: 1rem;
}
.buttons button#next {
position: absolute;
top: 50%;
right: 1rem;
}
.buttons button {
border: 2px solid #e5ebf3;
background-color: transparent;
color: #e5ebf3;
cursor: pointer;
padding: 13px 15px;
border-radius: 50%;
outline: none;
}
.buttons button:hover {
background-color: #e5ebf3;
color: #362a2b;
}
@media (min-width: 640px) and (min-height: 640px) {
.slide .content {
bottom: 70px;
left: -600px;
width: 600px;
padding: 2rem;
line-height: 1.6;
}
.slide .content h1 {
font-size: 2rem;
}
.slide.current .content {
transform: translateX(600px);
}
}
</style>
</head>
<body>
<!-- partial:index.partial.html -->
<div class="slider">
<div class="slide current"></div>
<div class="slide"></div>
<div class="slide"></div>
</div>
<div class="buttons">
<button id="prev"><i class="fas fa-arrow-left"></i></button>
<button id="next"><i class="fas fa-arrow-right"></i></button>
</div>
<!-- partial -->
<script>
const slides = document.querySelectorAll(".slide");
const nextButton = document.getElementById("next");
const prevButton = document.getElementById("prev");
const auto = true;
const intervalTime = 5000;
let slideInterval;
const nextSlide = () => {
const current = document.querySelector(".current");
current.classList.remove("current");
if (current.nextElementSibling) {
current.nextElementSibling.classList.add("current");
} else {
slides[0].classList.add("current");
}
};
const prevSlide = () => {
const current = document.querySelector(".current");
current.classList.remove("current");
if (current.previousElementSibling) {
current.previousElementSibling.classList.add("current");
} else {
slides[slides.length - 1].classList.add("current");
}
};
nextButton.addEventListener("click", () => {
nextSlide();
if (auto) {
clearInterval(slideInterval);
slideInterval = setInterval(nextSlide, intervalTime);
}
});
prevButton.addEventListener("click", () => {
prevSlide();
if (auto) {
clearInterval(slideInterval);
slideInterval = setInterval(nextSlide, intervalTime);
}
});
if (auto) {
slideInterval = setInterval(nextSlide, intervalTime);
}
</script>
</body>
</html>