-
Notifications
You must be signed in to change notification settings - Fork 0
/
sliderEffect06.html
339 lines (313 loc) · 14.7 KB
/
sliderEffect06.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>슬라이드 이펙트 06</title>
<link rel="stylesheet" href="../assets/css/slider.css">
<link rel="stylesheet" href="../assets/css/dracula.css">
<style>
/* slider */
.slider__wrap {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.slider__img { /* 이미지를 보이는 영역 */
position: relative;
width: 800px;
height: 450px;
overflow: hidden;
}
.slider__inner { /* 이미지를 감싸고 있는 부모 : 움직이는 부분 */
display: flex;
flex-wrap: wrap;
width: 10000px; /* 총 이미지 6개 */
height: 450px;
position: relative;
left: -800px;
}
.slider__inner.transition {
transition: all 0.5s;
}
.slider { /* 개별적인 이미지 */
position: relative;
width: 800px;
height: 450px;
}
.slider span {
position: absolute;
left: 5px;
top: 5px;
background: rgba(0, 0, 0, 0.4);
color: #fff;
padding: 5px 10px;
}
@media(max-width: 800px) {
.slider__img {
position: relative;
width: 400px;
height: 225px;
}
}
.slider__btn button {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 50px;
height: 50px;
background: rgba(0,0,0,0.4);
text-align: center;
line-height: 48px;
transition: all 0.2s;
display: block;
color: #fff;
pointer-events: auto;
border: 0;
cursor: pointer;
}
.slider__btn button:hover {
border-radius: 50%;
background: #3b3d6350;
}
.slider__btn.disable button {
pointer-events: none;
}
.slider__btn button.prev{
left: 0;
}
.slider__btn button.next{
right: 0;
}
.slider__dot {
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 20px;
}
.slider__dot .dot {
width: 20px;
height: 20px;
background: rgba(0, 0, 0, 0.4);
display: inline-block;
border-radius: 50%;
text-indent: -9999px;
transition: all 0.3s;
margin: 3px;
}
.slider__dot .dot.active {
background: rgba(255, 255, 255, 0.4);
}
</style>
</head>
<body class="img04 jeju">
<!-- header -->
<header id="header">
<h1>Javascript Slider Effect06</h1>
<p>슬라이드 이펙트 - 이미지 슬라이드(버튼, 닷메뉴, 무한)</p>
<ul>
<li><a href="sliderEffect01.html">1</a></li>
<li><a href="sliderEffect02.html">2</a></li>
<li><a href="sliderEffect03.html">3</a></li>
<li><a href="sliderEffect04.html">4</a></li>
<li><a href="sliderEffect05.html">5</a></li>
<li class="active"><a href="sliderEffect06.html">6</a></li>
<li><a href="sliderEffect07.html">7</a></li>
</ul>
</header>
<!-- main -->
<main id="main">
<section id="sliderType03">
<div class="slider__wrap">
<div class="slider__img">
<div class="slider__inner">
<div class="slider s1"><span>이미지1</span><img src="../assets/img/slide01.jpg" alt="이미지1"></div>
<div class="slider s2"><span>이미지2</span><img src="../assets/img/slide02.jpg" alt="이미지2"></div>
<div class="slider s3"><span>이미지3</span><img src="../assets/img/slide03.jpg" alt="이미지3"></div>
<div class="slider s4"><span>이미지4</span><img src="../assets/img/slide04.jpg" alt="이미지4"></div>
<div class="slider s5"><span>이미지5</span><img src="../assets/img/slide05.jpg" alt="이미지5"></div>
</div>
</div>
<div class="slider__btn">
<button href="#" class="prev">prev</button>
<button href="#" class="next">next</button>
</div>
<div class="slider__dot">
<!-- <a href="#" class="dot active">image01</a>
<a href="#" class="dot">image02</a>
<a href="#" class="dot">image03</a>
<a href="#" class="dot">image04</a>
<a href="#" class="dot">image05</a> -->
</div>
</div>
</section>
</main>
<!-- footer -->
<footer id="footer">
<div class="modal__wrap">
<div class="modal__btn">소스 보기</div>
<div class="modal__cont">
<div class="modal__box">
<div class="title">
<span class="dot" aria-label="true"></span>
<div class="tabs">
<div class="active">
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="navy" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="var(--red-0)"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill=yellow></path>
</svg>
</span>
<em>Javascript</em>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div>
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="navy" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="var(--red-0)"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill=yellow></path>
</svg>
</span>
<em>HTML</em>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div>
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="navy" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="var(--red-0)"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill=yellow></path>
</svg>
</span>
<em>CSS</em>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
</div>
<span class="plus" arra-label="true">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M2.5 8H13.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M8 2.5V13.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div class="cont">
<div class="active">
<pre><code class="language-js">
</code></pre>
</div>
<div>
<pre><code class="language-js">
</code></pre>
</div>
<div>
<pre><code class="language-js">
</code></pre>
</div>
</div>
</div>
<div class="modal__close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
</div>
</div>
</footer>
<script src="../assets/js/highlight.min.js"></script>
<script src="../assets/js/common.js"></script>
<script>
hljs.highlightAll();
</script>
<script>
const sliderWrap = document.querySelector(".slider__wrap"); // 전체 이미지 슬라이드
const sliderImg = document.querySelector(".slider__img"); // 보여지는 영역
const sliderInner = document.querySelector(".slider__inner"); // 움직이는 영역
const slider = document.querySelectorAll(".slider"); // 이미지
const sliderDot = document.querySelector(".slider__dot"); // 닷 메뉴
const sliderBtn = document.querySelector(".slider__btn"); // 버튼
const sliderBtnPrev = document.querySelector(".slider__btn .prev"); // 왼쪽 버튼
const sliderBtnNext = document.querySelector(".slider__btn .next"); // 오른쪽 버튼
let currentIndex = 0,
sliderLength = slider.length,
sliderWidth = slider[0].offsetWidth,
sliderFirst = slider[0], // 첫번째 이미지
sliderLast = slider[sliderLength -1], // 마지막 이미지
cloneFirst = sliderFirst.cloneNode(true), // 첫번째 이미지 복사
cloneLast = sliderLast.cloneNode(true), // 마지막 이미지 복사
dotIndex = "";
sliderInner.appendChild(cloneFirst);
sliderInner.insertBefore(cloneLast, sliderFirst);
function init(){
// 이미지 갯수만큼 닷 메뉴 생기게
for(let i=0; i<sliderLength; i++){
dotIndex += "<a href='#' class='dot'></a>";
}
sliderDot.innerHTML = dotIndex;
sliderDot.firstElementChild.classList.add("active");
}
init();
function gotoSlider(direction){
sliderInner.classList.add("transition");
posInitial = sliderInner.offsetLeft;
console.log(posInitial)
if(direction == -1){
sliderInner.style.left = (posInitial + sliderWidth) + "px";
currentIndex--;
} else if(direction == 1){
sliderInner.style.left = (posInitial - sliderWidth) + "px";
currentIndex++;
}
}
// 순간이동 메서드
function checkIndex() {
sliderInner.classList.remove("transition");
// sliderBtn.classList.add("disable");
console.log(currentIndex);
// 마지막 이미지
if(currentIndex == sliderLength) {
sliderInner.style.left = -(1 * sliderWidth) + "px";
currentIndex = 0;
}
// 처음 이미지
if(currentIndex == -1) {
sliderInner.style.left = -(sliderLength * sliderWidth) + "px";
currentIndex = sliderLength - 1;
}
}
sliderBtnPrev.addEventListener("click", () => {
gotoSlider(-1);
setTimeout(() => {
sliderBtn.classList.remove("disable");
},300);
});
sliderBtnNext.addEventListener("click", () => {
gotoSlider(1);
setTimeout(() => {
sliderBtn.classList.remove("disable");
},300);
});
sliderInner.addEventListener("transitionend", checkIndex);
</script>
</body>
</html>