-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown-timer.html
More file actions
201 lines (173 loc) · 6.5 KB
/
Copy pathcountdown-timer.html
File metadata and controls
201 lines (173 loc) · 6.5 KB
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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>카운트다운 타이머</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Malgun Gothic', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}
.container {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: clamp(20px, 5vw, 50px);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
text-align: center;
width: 100%;
margin: clamp(20px, 5vw, 50px);
}
.title {
color: white;
font-size: clamp(16px, 4vw, 24px);
font-weight: bold;
margin-bottom: clamp(20px, 4vw, 40px);
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
.countdown {
display: flex;
justify-content: center;
align-items: center;
gap: clamp(5px, 1.5vw, 10px);
margin-bottom: clamp(20px, 4vw, 40px);
flex-wrap: nowrap;
}
.time-box {
background: rgba(255, 255, 255, 0.25);
backdrop-filter: blur(5px);
border-radius: clamp(5px, 1.5vw, 10px);
padding: clamp(10px, 3vw, 20px);
min-width: clamp(40px, 10vw, 70px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
flex-shrink: 0;
}
.time-number {
color: white;
font-size: clamp(24px, 7vw, 48px);
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
line-height: 1;
}
.separator {
color: white;
font-size: clamp(24px, 7vw, 48px);
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
flex-shrink: 0;
}
.message {
color: white;
font-size: clamp(14px, 3vw, 18px);
font-weight: 500;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}
.completed {
font-size: 32px;
color: #ffd700;
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
</style>
</head>
<body>
<div class="container">
<div class="title" id="mainTitle">남은 선착순 할인 수량 : 18개</div>
<div class="countdown" id="countdown">
<div class="time-box">
<div class="time-number" id="hours1">0</div>
</div>
<div class="time-box">
<div class="time-number" id="hours2">0</div>
</div>
<div class="separator">:</div>
<div class="time-box">
<div class="time-number" id="minutes1">0</div>
</div>
<div class="time-box">
<div class="time-number" id="minutes2">0</div>
</div>
<div class="separator">:</div>
<div class="time-box">
<div class="time-number" id="seconds1">0</div>
</div>
<div class="time-box">
<div class="time-number" id="seconds2">0</div>
</div>
</div>
<div class="message" id="message">마감 시 "할인 전 가격"으로 올라갑니다.</div>
</div>
<script>
// URL 파라미터에서 값 가져오기
function getUrlParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// URL 파라미터에서 설정 읽기 (없으면 기본값 사용)
const REMAINING_QUANTITY = getUrlParameter('qty') || 18;
const DEADLINE = getUrlParameter('deadline') || '20251022 1030';
let timerInterval;
function parseDeadline(deadlineStr) {
// 공백 제거
deadlineStr = deadlineStr.replace(/\s+/g, '');
const year = deadlineStr.substring(0, 4);
const month = deadlineStr.substring(4, 6);
const day = deadlineStr.substring(6, 8);
const hour = deadlineStr.substring(8, 10);
const minute = deadlineStr.substring(10, 12);
return new Date(year, month - 1, day, hour, minute, 0).getTime();
}
function initTimer() {
document.getElementById('mainTitle').textContent =
`남은 선착순 할인 수량 : ${REMAINING_QUANTITY}개`;
const targetTime = parseDeadline(DEADLINE);
if (timerInterval) {
clearInterval(timerInterval);
}
timerInterval = setInterval(() => updateCountdown(targetTime), 1000);
updateCountdown(targetTime);
}
function updateCountdown(targetTime) {
const now = new Date().getTime();
const distance = targetTime - now;
if (distance < 0) {
clearInterval(timerInterval);
document.getElementById('countdown').innerHTML =
'<div class="completed">⏰ 시간 종료!</div>';
return;
}
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
const h = String(hours).padStart(2, '0');
const m = String(minutes).padStart(2, '0');
const s = String(seconds).padStart(2, '0');
document.getElementById('hours1').textContent = h[0];
document.getElementById('hours2').textContent = h[1];
document.getElementById('minutes1').textContent = m[0];
document.getElementById('minutes2').textContent = m[1];
document.getElementById('seconds1').textContent = s[0];
document.getElementById('seconds2').textContent = s[1];
}
initTimer();
</script>
</body>
</html>