-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
577 lines (515 loc) · 16.5 KB
/
index.html
File metadata and controls
577 lines (515 loc) · 16.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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Flip Clock</title>
<style>
/* ----------------------
Basic page layout
---------------------- */
:root{
--bg: #0f1724;
--card: #0b1220;
--muted: #9aa6b2;
--accent: #00d1ff;
--glass: rgba(255,255,255,0.03);
--glass-2: rgba(255,255,255,0.02);
--font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
html,body{
height:100%;
margin:0;
font-family:var(--font-sans);
background: linear-gradient(180deg, #071023 0%, #071827 60%);
color:#e6eef3;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
}
header{
display:flex;
align-items:center;
justify-content:space-between;
padding:18px 28px;
gap:12px;
border-bottom:1px solid rgba(255,255,255,0.03);
background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
}
.brand{
display:flex;
align-items:center;
gap:12px;
}
.logo {
width:44px;
height:44px;
display:inline-grid;
place-items:center;
font-weight:700;
color:var(--bg);
background:linear-gradient(135deg,var(--accent),#3b82f6);
border-radius:8px;
box-shadow: 0 4px 18px rgba(3,7,18,0.6);
}
nav a {
color:var(--muted);
text-decoration:none;
margin-left:18px;
font-size:15px;
}
nav a:hover{ color:var(--accent); text-decoration:underline; }
main {
display:grid;
grid-template-columns: 1fr 380px;
gap:28px;
max-width:1100px;
margin:32px auto;
padding:0 20px;
align-items:start;
}
.card {
background: linear-gradient(180deg,var(--card), #071226 80%);
border-radius:12px;
padding:22px;
box-shadow: 0 8px 30px rgba(2,6,12,0.6);
border: 1px solid rgba(255,255,255,0.02);
}
/* ----------------------
Flip clock styles
---------------------- */
.clock {
display:flex;
gap:12px;
align-items:center;
justify-content:center;
padding:18px;
flex-wrap:wrap;
}
.unit {
--w:88px;
width:var(--w);
min-width:var(--w);
perspective: 1000px;
}
.label {
font-size:12px;
color:var(--muted);
text-align:center;
margin-bottom:8px;
text-transform:uppercase;
letter-spacing:1px;
}
.flip-card {
position:relative;
height:96px;
width:100%;
border-radius:8px;
overflow:visible;
}
.flip-inner {
position:relative;
height:100%;
width:100%;
transform-style: preserve-3d;
}
/* top & bottom plates */
.plate {
position:absolute;
left:0; right:0;
height:50%;
overflow:hidden;
backface-visibility:hidden;
border-radius:8px;
display:flex;
align-items:center;
justify-content:center;
font-weight:700;
font-size:40px;
color:#0b1220;
background:linear-gradient(180deg,#ffffff,#f0f6ff);
box-shadow: 0 6px 18px rgba(2,6,12,0.35), inset 0 -1px rgba(0,0,0,0.06);
}
.plate.top {
top:0;
transform-origin: bottom;
border-bottom-left-radius:0;
border-bottom-right-radius:0;
}
.plate.bottom {
bottom:0;
transform-origin: top;
border-top-left-radius:0;
border-top-right-radius:0;
}
/* front/back halves used in animation */
.flip {
position:absolute;
left:0; right:0;
height:100%;
transform-style:preserve-3d;
pointer-events:none;
}
.flip .front,
.flip .back {
position:absolute;
left:0; right:0;
height:50%;
display:flex;
align-items:center;
justify-content:center;
backface-visibility:hidden;
font-weight:700;
font-size:40px;
color:#0b1220;
border-radius:8px;
}
.flip .front {
top:0;
transform-origin: bottom;
background:linear-gradient(180deg,#ffffff,#eef6ff);
box-shadow: 0 6px 18px rgba(2,6,12,0.25), inset 0 -1px rgba(0,0,0,0.03);
border-bottom-left-radius:0;
border-bottom-right-radius:0;
overflow:hidden;
}
.flip .back {
bottom:0;
transform-origin: top;
background:linear-gradient(180deg,#f6fbff,#e9f7ff);
box-shadow: 0 -6px 18px rgba(2,6,12,0.08);
border-top-left-radius:0;
border-top-right-radius:0;
transform: rotateX(180deg);
}
/* small separator line */
.split {
position:absolute;
left:4%;
right:4%;
top:50%;
height:2px;
transform:translateY(-50%);
background:linear-gradient(90deg, rgba(0,0,0,0.06), rgba(255,255,255,0.02));
z-index:6;
}
/* Colon */
.colon {
color:var(--muted);
font-size:36px;
margin:0 6px;
width:22px;
text-align:center;
}
/* animation classes */
.flip.animate-top .front {
animation:foldTop 450ms ease-in forwards;
}
.flip.animate-top .back {
animation:holdBack 450ms ease-in forwards;
}
.flip.animate-bottom .back {
animation:unfoldBottom 450ms ease-out forwards;
}
.flip.animate-bottom .front {
animation:holdFront 450ms ease-out forwards;
}
@keyframes foldTop {
0% { transform: rotateX(0deg); }
100% { transform: rotateX(-180deg); }
}
@keyframes unfoldBottom {
0% { transform: rotateX(180deg); }
100% { transform: rotateX(0deg); }
}
@keyframes holdBack {
0% { transform: rotateX(180deg); opacity:0; }
40% { transform: rotateX(180deg); opacity:1; }
100% { transform: rotateX(180deg); opacity:1; }
}
@keyframes holdFront {
0% { transform: rotateX(0deg); opacity:1; }
60% { transform: rotateX(0deg); opacity:1; }
100% { transform: rotateX(0deg); opacity:1; }
}
/* Right column: content */
.aside {
position:sticky;
top:28px;
align-self:start;
}
h1 {
margin:0 0 8px 0;
font-size:22px;
}
p.lead {
margin:8px 0 16px 0;
color:var(--muted);
line-height:1.5;
}
.meta {
font-size:13px;
color:var(--muted);
margin-bottom:12px;
}
a.cta {
display:inline-block;
margin-top:8px;
padding:8px 12px;
border-radius:8px;
background:linear-gradient(90deg,var(--accent),#3b82f6);
color:var(--bg);
text-decoration:none;
font-weight:600;
}
footer {
max-width:1100px;
margin:28px auto;
color:var(--muted);
font-size:14px;
padding:0 20px 40px 20px;
text-align:center;
}
/* Responsiveness */
@media (max-width:920px){
main{ grid-template-columns: 1fr; }
.aside { position:relative; top:auto; }
.unit{ --w:72px; }
.flip-card{ height:78px; }
.plate{ font-size:32px; height:50%; }
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="logo">FB</div>
<div>
<div style="font-weight:700; font-size:16px;">Flip Clock </div>
<div class="meta" style="margin-top:4px;">Flip Clock Online</div>
</div>
</div>
<nav>
<!-- Top menu anchor requested by user -->
<a href="https://flipclock.io/" target="_blank" rel="noopener noreferrer">Flip Clock</a>
<a href="#about">About</a>
<a href="#howto">How to Use</a>
</nav>
</header>
<main>
<section class="card">
<h1>Live Flip Clock</h1>
<p class="lead">This flip clock shows the current local time and updates with a smooth flip animation. It is implemented using only HTML, CSS and JavaScript — perfect to include in small projects, landing pages, or teaching demos.</p>
<div class="clock" aria-live="polite" aria-label="Flip clock showing hours minutes and seconds">
<!-- Hours -->
<div class="unit" data-unit="hours">
<div class="label">Hours</div>
<div class="flip-card" aria-hidden="false">
<div class="flip-inner">
<div class="plate top" id="hours-top">00</div>
<div class="plate bottom" id="hours-bottom">00</div>
<div class="flip" id="hours-flip" aria-hidden="true">
<div class="front" id="hours-front">00</div>
<div class="back" id="hours-back">00</div>
</div>
<div class="split"></div>
</div>
</div>
</div>
<div class="colon">:</div>
<!-- Minutes -->
<div class="unit" data-unit="minutes">
<div class="label">Minutes</div>
<div class="flip-card">
<div class="flip-inner">
<div class="plate top" id="mins-top">00</div>
<div class="plate bottom" id="mins-bottom">00</div>
<div class="flip" id="mins-flip">
<div class="front" id="mins-front">00</div>
<div class="back" id="mins-back">00</div>
</div>
<div class="split"></div>
</div>
</div>
</div>
<div class="colon">:</div>
<!-- Seconds -->
<div class="unit" data-unit="seconds">
<div class="label">Seconds</div>
<div class="flip-card">
<div class="flip-inner">
<div class="plate top" id="secs-top">00</div>
<div class="plate bottom" id="secs-bottom">00</div>
<div class="flip" id="secs-flip">
<div class="front" id="secs-front">00</div>
<div class="back" id="secs-back">00</div>
</div>
<div class="split"></div>
</div>
</div>
</div>
</div>
<div style="margin-top:20px; color:var(--muted); font-size:13px;">
<strong>Note:</strong> The flip animation triggers only when the corresponding value changes. Hours use 24-hour format by default.
</div>
</section>
<aside class="aside">
<div class="card">
<h2 id="about">About Flip Clocks</h2>
<p class="meta">What is a flip clock?</p>
<p>Flip clocks are mechanical or digital displays where numbers 'flip' like cards to reveal the next value. They were popularized in the mid-20th century for alarm clocks and public displays. The characteristic motion — a hinged card flipping — is visually satisfying and easy to mimic with CSS 3D transforms.</p>
<h3 style="margin-top:12px;">Real-world uses</h3>
<ul style="color:var(--muted); line-height:1.45;">
<li>Landing pages showing current time or countdowns.</li>
<li>Event pages with countdown timers causing high engagement.</li>
<li>Dashboard widgets for a retro / physical display look.</li>
</ul>
<a class="cta" href="https://flipclock.io/" target="_blank" rel="noopener noreferrer">Visit flipclock.io</a>
<h3 id="howto" style="margin-top:16px;">How to adapt</h3>
<ol style="color:var(--muted); line-height:1.5; padding-left:18px;">
<li>Change 24/12-hour format: adapt the hours calculation in JS.</li>
<li>Remove seconds: hide the seconds unit and stop its interval.</li>
<li>Styling: update CSS variables at the top (accent, background).</li>
</ol>
</div>
<div class="card" style="margin-top:14px;">
<h3>Customization tips</h3>
<p style="color:var(--muted); line-height:1.4;">
Use `requestAnimationFrame` sparingly — this implementation uses `setInterval` for seconds for simplicity. For production use you can reduce work by updating only changed units and debouncing animation triggers.
</p>
</div>
</aside>
</main>
<footer>
Built with ❤
</footer>
<script>
// ----------------------------
// Flip Clock JavaScript
// ----------------------------
// Utility: pad with leading zero
function pad(num) {
return String(num).padStart(2, '0');
}
// Get references
const refs = {
hours: {
top: document.getElementById('hours-top'),
bottom: document.getElementById('hours-bottom'),
flip: document.getElementById('hours-flip'),
front: document.getElementById('hours-front'),
back: document.getElementById('hours-back')
},
minutes: {
top: document.getElementById('mins-top'),
bottom: document.getElementById('mins-bottom'),
flip: document.getElementById('mins-flip'),
front: document.getElementById('mins-front'),
back: document.getElementById('mins-back')
},
seconds: {
top: document.getElementById('secs-top'),
bottom: document.getElementById('secs-bottom'),
flip: document.getElementById('secs-flip'),
front: document.getElementById('secs-front'),
back: document.getElementById('secs-back')
}
};
// Current displayed values
let current = {
h: null,
m: null,
s: null
};
// Update a single unit with a flip animation when value changes
function updateUnit(unitRef, newVal) {
const topEl = unitRef.top;
const bottomEl = unitRef.bottom;
const flipEl = unitRef.flip;
const frontEl = unitRef.front;
const backEl = unitRef.back;
const oldVal = topEl.textContent;
if (oldVal === newVal) return; // nothing to do
// Set up visuals for animation
frontEl.textContent = oldVal; // visible top (will fold)
backEl.textContent = newVal; // back of flip (hidden initially)
bottomEl.textContent = newVal; // bottom permanent element after flip
// Trigger top-fold animation
flipEl.classList.remove('animate-top','animate-bottom');
// Force reflow so that animation can play when we add classes
void flipEl.offsetWidth;
// animate top fold
flipEl.classList.add('animate-top');
// After the fold finishes (~450ms), animate bottom unfold
setTimeout(() => {
// Reveal the new top value
topEl.textContent = newVal;
// swap to bottom unfold
flipEl.classList.remove('animate-top');
flipEl.classList.add('animate-bottom');
// Cleanup after animation completes
setTimeout(() => {
flipEl.classList.remove('animate-bottom');
// ensure final state matches
topEl.textContent = newVal;
bottomEl.textContent = newVal;
frontEl.textContent = newVal;
backEl.textContent = newVal;
}, 480);
}, 230); // start bottom unfold while fold is midway for nicer effect
}
// Main tick: read current time and update units
function tick() {
const now = new Date();
let h = now.getHours(); // 0 - 23
let m = now.getMinutes();
let s = now.getSeconds();
// If you prefer 12-hour format, uncomment and adjust:
// const is12Hour = false;
// if (is12Hour) {
// h = h % 12 || 12;
// }
const sh = pad(h);
const sm = pad(m);
const ss = pad(s);
// Update only changed units
if (current.h !== sh) {
updateUnit(refs.hours, sh);
current.h = sh;
}
if (current.m !== sm) {
updateUnit(refs.minutes, sm);
current.m = sm;
}
if (current.s !== ss) {
updateUnit(refs.seconds, ss);
current.s = ss;
}
}
// Initialize the clock visuals without animations
function init() {
const now = new Date();
current.h = pad(now.getHours());
current.m = pad(now.getMinutes());
current.s = pad(now.getSeconds());
refs.hours.top.textContent = current.h;
refs.hours.bottom.textContent = current.h;
refs.hours.front.textContent = current.h;
refs.hours.back.textContent = current.h;
refs.minutes.top.textContent = current.m;
refs.minutes.bottom.textContent = current.m;
refs.minutes.front.textContent = current.m;
refs.minutes.back.textContent = current.m;
refs.seconds.top.textContent = current.s;
refs.seconds.bottom.textContent = current.s;
refs.seconds.front.textContent = current.s;
refs.seconds.back.textContent = current.s;
}
// Start
init();
// Tick every 250ms to capture transitions reliably (updates only when changed)
setInterval(tick, 250);
// Accessibility: allow page to announce time changes for screen readers
// (aria-live on the .clock region helps; additional dynamic announcements can be added if needed)
</script>
</body>
</html>