/
s3.html
184 lines (174 loc) · 5.99 KB
/
s3.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
<!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>웹디자인기능사 슬라이드 S-3</title>
<link href="https://webfontworld.github.io/gmarket/GmarketSans.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
font-family: 'GmarketSans';
}
#wrap {
width: 1200px;
margin: 0 auto;
}
#header {
width: 100%;
display: flex;
}
#header .logo {
width: 20%;
height: 100px;
background-color: #efefef;
}
#header .nav {
width: 80%;
height: 100px;
background-color: #e3e3e3;
}
#slider {
width: 100%;
height: 300px;
background-color: #d9d9d9;
}
#contents {
width: 100%;
display: flex;
}
#contents .content1 {
width: 33.3333%;
height: 200px;
background-color: #d1d1d1;
}
#contents .content2 {
width: 33.3333%;
height: 200px;
background-color: #c7c7c7;
}
#contents .content3 {
width: 33.3333%;
height: 200px;
background-color: #bcbcbc;
}
#footer {
width: 100%;
display: flex;
}
#footer .footer1 {
width: 20%;
height: 100px;
background-color: #b1b1b1;
}
#footer .footer2 {
width: 60%;
height: 100px;
background-color: #a3a3a3;
}
#footer .footer3 {
width: 20%;
height: 100px;
background-color: #9d9d9d;
}
/* slider */
#slider {
overflow: hidden;
}
.sliderWrap .slider {
position: relative;
}
.sliderWrap .slider img {
vertical-align: top;
}
.sliderWrap .slider span {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0,0,0,0.3);
color: #fff;
padding: 10px 20px;
}
</style>
</head>
<body>
<div id="wrap">
<header id="header">
<h1 class="logo"></h1>
<nav class="nav"></nav>
</header>
<!-- //header -->
<article id="slider">
<div class="sliderWrap">
<div class="slider s1">
<img src="https://webstoryboy.github.io/webstoryboy/w_webd/slider/slider01.jpg" alt="이미지 설명">
<span>이미지1</span>
</div>
<div class="slider s2">
<img src="https://webstoryboy.github.io/webstoryboy/w_webd/slider/slider02.jpg" alt="이미지 설명">
<span>이미지2</span>
</div>
<div class="slider s3">
<img src="https://webstoryboy.github.io/webstoryboy/w_webd/slider/slider03.jpg" alt="이미지 설명">
<span>이미지3</span>
</div>
</div>
</article>
<!-- //slider -->
<main id="contents">
<section class="content1"></section>
<section class="content2"></section>
<section class="content3"></section>
</main>
<!-- //contents -->
<footer id="footer">
<div class="footer1"></div>
<div class="footer2"></div>
<div class="footer3"></div>
</footer>
<!-- //footer -->
</div>
<!-- //wrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- <script>
$(function(){
let currentIndex = 0; //현재 이미지 설정
$(".sliderWrap").append($(".slider").first().clone(true)); //첫번째 이미지를 복사해서 마지막에 추가
setInterval(function(){ //3초에 한번씩 실행
currentIndex++; //현재 이미지를 1씩 증가
$(".sliderWrap").animate({marginTop: -currentIndex * 300 + "px"}, 600); //이미지 애니메이션
if(currentIndex == 3){ //마지막 이미지
setTimeout(function(){
$(".sliderWrap").animate({ marginTop:0 }, 0); //애니메이션 초기화
currentIndex = 0; //현재 이미지를 초기화
}, 700)
}
}, 3000);
});
</script> -->
<script>
window.onload = function(){
let currentIndex = 0; //현재 이미지 설정
const sliderWrap = document.querySelector(".sliderWrap"); //전체 이미지
const slider = document.querySelectorAll(".slider"); //각각의 이미지
const sliderClone = sliderWrap.firstElementChild.cloneNode(true); //첫번째 이미지를 저장
sliderWrap.appendChild(sliderClone);
setInterval(() => { //3초에 한번씩 실행
currentIndex++; //현재 이미지 1씩 증가
sliderWrap.style.transition = "all 0.6s"; //애니메이션 추가
sliderWrap.style.marginTop = -currentIndex * 300 + "px"; //이미지 이동
if(currentIndex == slider.length){ //마지막 이미지
setTimeout(() => {
sliderWrap.style.transition = "0s"; //애니메이션 정지
sliderWrap.style.marginTop = "0"; //이미지 위치 초기화
currentIndex = 0; //현재 이미지 초기화
}, 700);
}
}, 3000);
}
</script>
</body>
</html>