-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
618 lines (545 loc) · 17.5 KB
/
Copy pathindex.html
File metadata and controls
618 lines (545 loc) · 17.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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>appear-on-scroll demo</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;1,500&display=swap"
rel="stylesheet"
/>
<style>
:root {
--bg: #0d1014;
--surface: #14181e;
--border: #222831;
--text: #e8ebef;
--muted: #8a929d;
/* One accent for the whole page: warm, against a cool near-black. */
--accent: #d9944a;
/* Two radii, and only two: hairlines and cards. */
--r-sm: 3px;
--r: 8px;
--nav-height: 64px;
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
* {
box-sizing: border-box;
}
html {
/* The scrollbar, form controls and overscroll all take the page's theme. */
color-scheme: dark;
background: var(--bg);
}
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
'IBM Plex Sans',
ui-sans-serif,
system-ui,
-apple-system,
sans-serif;
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
::selection {
background: rgb(217 148 74 / 0.35);
color: var(--text);
}
/* This page is about scrolling, so the thing you are moving should be
visible and take the page's colours rather than the browser's. Styling
these pseudo-elements also opts Chromium out of overlay scrollbars, so
the bar holds its own column instead of floating over the content and
fading away. Firefox takes the two-value form below. */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: var(--surface);
}
::-webkit-scrollbar-thumb {
background: #3c4552;
border-radius: var(--r-sm);
border: 2px solid var(--surface);
}
::-webkit-scrollbar-thumb:hover {
background: var(--accent);
}
@supports not selector(::-webkit-scrollbar) {
html {
scrollbar-width: thin;
scrollbar-color: #3c4552 var(--surface);
}
}
/* macOS hides the real scrollbar until you scroll, and never shows it in a
screen capture, so the page carries its own position marker. It rides a
scroll timeline rather than a scroll listener: no JavaScript, and none of
the per-frame work this library exists to avoid. Browsers without scroll
timelines get nothing, which is why the rail is hidden by default. */
.rail {
display: none;
position: fixed;
top: 0;
right: 0;
z-index: 5;
width: 5px;
height: 100vh;
height: 100dvh;
background: var(--border);
}
.rail span {
display: block;
width: 100%;
height: 56px;
border-radius: var(--r-sm);
background: var(--accent);
}
@supports (animation-timeline: scroll()) {
.rail {
display: block;
}
.rail span {
animation: rail linear;
animation-timeline: scroll(root block);
}
}
@keyframes rail {
from {
transform: translateY(0);
}
to {
transform: translateY(calc(100dvh - 56px));
}
}
a {
color: var(--text);
text-decoration-thickness: 1px;
text-underline-offset: 0.18em;
text-decoration-color: var(--muted);
}
a:hover {
text-decoration-color: var(--accent);
}
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
border-radius: var(--r-sm);
}
main {
max-width: 880px;
margin: 0 auto;
padding: 0 24px;
}
h1,
h2,
h3 {
text-wrap: balance;
}
p {
text-wrap: pretty;
}
.top {
display: flex;
align-items: center;
justify-content: space-between;
height: var(--nav-height);
font-size: 0.95rem;
}
.top .name {
font-weight: 500;
text-decoration: none;
}
.top .links {
display: flex;
gap: 20px;
}
.hero {
position: relative;
/* Fill the first screen minus the bar above it, using the small viewport
so the caret does not jump when a phone's address bar collapses. */
min-height: calc(100vh - var(--nav-height));
min-height: calc(100svh - var(--nav-height));
display: flex;
flex-direction: column;
justify-content: center;
gap: 14px;
padding-bottom: 12vh;
}
.hero h1 {
font-size: clamp(2.2rem, 5.2vw, 3.5rem);
font-weight: 600;
/* Display type sets its own leading; the body's 1.6 leaves headlines
floating apart. 1.08 still clears the italic's descenders. */
line-height: 1.08;
margin: 0;
letter-spacing: -0.02em;
max-width: 18ch;
}
/* Emphasis inside a headline belongs to the same typeface. Italic reads as
intent; a gradient fill reads as decoration looking for a job. */
.hero h1 em {
font-style: italic;
font-weight: 500;
/* Descender clearance, so the italic never clips against tight leading. */
line-height: 1.1;
padding-bottom: 0.06em;
}
.hero p {
color: var(--muted);
font-size: 1.05rem;
max-width: 44ch;
margin: 0;
}
/* The tease: an invitation to scroll, anchored to the foot of the first
screen. It nudges down and then rests, rather than metronoming, so it
reads as a gesture rather than a loading indicator. */
.tease {
position: absolute;
bottom: 4vh;
left: 50%;
display: grid;
place-items: center;
width: 44px;
height: 44px;
padding: 0;
background: none;
border: 0;
border-radius: 999px;
color: var(--accent);
cursor: pointer;
transform: translateX(-50%);
transition: transform 160ms var(--ease-out);
}
/* Press feedback lives on the button, not the bobbing span: the keyframe
animation owns that span's transform and would swallow it. */
.tease:active {
transform: translateX(-50%) scale(0.94);
}
.tease:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
@media (hover: hover) and (pointer: fine) {
.tease:hover .chevron {
opacity: 1;
}
}
.tease:focus-visible .chevron {
opacity: 1;
}
.bob {
display: block;
animation: bob 1.5s ease-in-out infinite;
}
.chevron {
display: block;
width: 13px;
height: 13px;
margin-top: -5px;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: rotate(45deg);
opacity: 0.75;
transition: opacity 200ms ease;
}
@keyframes bob {
0% {
transform: translateY(0);
}
45% {
transform: translateY(8px);
}
70%,
100% {
transform: translateY(0);
}
}
@media (prefers-reduced-motion: reduce) {
.bob {
animation: none;
}
.tease {
transition: none;
}
}
/* Each example gets a screen's worth of room, so its reveal is seen alone. */
section {
padding: 22vh 0;
border-top: 1px solid var(--border);
}
section h2 {
margin: 0 0 8px;
font-size: 1.75rem;
font-weight: 600;
line-height: 1.2;
letter-spacing: -0.02em;
}
section > p {
color: var(--muted);
margin: 0 0 40px;
max-width: 62ch;
}
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--r);
padding: 28px;
}
.card h3 {
margin: 0 0 6px;
font-size: 1.05rem;
font-weight: 600;
}
.card p {
margin: 0;
color: var(--muted);
font-size: 0.9rem;
}
.row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}
/* A lone card should look like a card, not a banner. */
.row.single {
grid-template-columns: minmax(0, 420px);
}
/* The left and right examples travel 40px sideways while hidden. On a phone
the cards are full width, so that travel would reach past the viewport and
give the page a horizontal scrollbar. Clip contains it without creating a
scroll container, so the slide still reads as arriving from the edge. */
#directions .row {
overflow-x: clip;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
.grid .card {
aspect-ratio: 4 / 3;
display: flex;
flex-direction: column;
justify-content: space-between;
font-size: 0.85rem;
color: var(--muted);
}
/* The numerals are the order of arrival: they are what the cascade shows. */
.stagger-cell b {
font-size: 1.6rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
color: var(--accent);
}
/* A bar per cell, so the cascade has a shape to travel along. */
.stagger-cell i {
display: block;
height: 5px;
border-radius: var(--r-sm);
background: var(--accent);
opacity: 0.5;
}
code {
font-family: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
font-size: 0.85em;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--r-sm);
padding: 2px 6px;
}
footer {
display: flex;
justify-content: space-between;
gap: 24px;
flex-wrap: wrap;
border-top: 1px solid var(--border);
padding: 40px 0 64px;
color: var(--muted);
font-size: 0.85rem;
}
footer p {
margin: 0;
}
footer > div {
display: grid;
gap: 6px;
}
@media (max-width: 640px) {
section {
padding: 18vh 0;
}
.card {
padding: 20px;
}
.grid {
gap: 10px;
}
.grid .card {
padding: 14px;
}
.stagger-cell b {
font-size: 1.25rem;
}
}
</style>
</head>
<body>
<div class="rail" aria-hidden="true"><span></span></div>
<main>
<nav class="top" aria-label="Site">
<a class="name" href="./">appear-on-scroll</a>
<span class="links">
<a href="https://www.npmjs.com/package/appear-on-scroll">npm</a>
<a href="https://github.com/davemaynard/appear-on-scroll">GitHub</a>
</span>
</nav>
<header class="hero">
<h1>Elements that <em>arrive</em> with the scroll.</h1>
<p>Reveal any element on scroll, with a slide that knows which way you scrolled. No dependencies.</p>
<button class="tease" type="button" aria-label="Scroll to the first example">
<span class="bob"><span class="chevron"></span></span>
</button>
</header>
<section id="slide">
<h2>Direction-aware slide</h2>
<p>
The default. Cards rise into place as you scroll down, and settle from above when you scroll back up to them.
The IntersectionObserver entry says which edge was crossed, so there is no scroll listener.
</p>
<div class="row">
<div class="card" data-slide id="dir-el">
<h3>Watch me twice</h3>
<p>Pass me going down, then come back up. I arrive from whichever side you approached.</p>
</div>
<div class="card" data-slide>
<h3>Same batch</h3>
<p>Everything in a section follows the same scroll direction.</p>
</div>
</div>
</section>
<section id="directions">
<h2>Pinned directions</h2>
<p>Set <code>direction</code> and the slide ignores which way you scrolled.</p>
<div class="row">
<div class="card" data-dir-up>
<h3>up</h3>
<p>Rises from below.</p>
</div>
<div class="card" data-dir-down>
<h3>down</h3>
<p>Drops from above.</p>
</div>
<div class="card" data-dir-left>
<h3>left</h3>
<p>Slides in from the right.</p>
</div>
<div class="card" data-dir-right>
<h3>right</h3>
<p>Slides in from the left.</p>
</div>
</div>
</section>
<section id="fade">
<h2>Fade</h2>
<p>
<code>animation: 'fade'</code>. No movement, only opacity. The v1 spelling, <code>slide: false</code>, still
works.
</p>
<div class="row single">
<div class="card" data-fade id="fade-el">
<h3>Fade</h3>
<p>The quiet option.</p>
</div>
</div>
</section>
<section id="zoom">
<h2>Zoom</h2>
<p><code>animation: 'zoom'</code> with <code>scale: 0.9</code>. Grows to full size while fading in.</p>
<div class="row single">
<div class="card" data-zoom>
<h3>Zoom</h3>
<p>Starts at 90% scale.</p>
</div>
</div>
</section>
<section id="blur">
<h2>Blur</h2>
<p><code>animation: 'blur'</code>. Sharpens into focus while fading in.</p>
<div class="row single">
<div class="card" data-blur>
<h3>Blur</h3>
<p>From soft focus to sharp.</p>
</div>
</div>
</section>
<section id="stagger">
<h2>Stagger</h2>
<p>
<code>stagger: 90</code>. Elements arriving together each wait 90ms longer than the one before, so a grid
cascades instead of popping in at once. The wave is measured in time rather than in observer batches, so the
cascade looks the same however fast you scrolled into it.
</p>
<div class="grid">
<div class="card stagger-cell"><b>01</b><i style="width: 64%"></i></div>
<div class="card stagger-cell"><b>02</b><i style="width: 42%"></i></div>
<div class="card stagger-cell"><b>03</b><i style="width: 88%"></i></div>
<div class="card stagger-cell"><b>04</b><i style="width: 30%"></i></div>
<div class="card stagger-cell"><b>05</b><i style="width: 74%"></i></div>
<div class="card stagger-cell"><b>06</b><i style="width: 52%"></i></div>
<div class="card stagger-cell"><b>07</b><i style="width: 96%"></i></div>
<div class="card stagger-cell"><b>08</b><i style="width: 38%"></i></div>
<div class="card stagger-cell"><b>09</b><i style="width: 68%"></i></div>
</div>
</section>
<section id="once">
<h2>Replay, or once</h2>
<p>
Elements hide again when they leave the viewport and replay on the way back. With <code>once: true</code> the
first appearance sticks.
</p>
<div class="row">
<div class="card" data-again id="again-el">
<h3>once: false</h3>
<p>Scroll away and back. I replay every time.</p>
</div>
<div class="card" data-once id="once-el">
<h3>once: true</h3>
<p>I appear once and never hide again.</p>
</div>
</div>
</section>
<footer>
<div>
<p>Zero dependencies. Under 3 KB gzipped. Honours <code>prefers-reduced-motion</code>.</p>
<p>npm still carries the 1.x line, which has a different API. Version 2 builds from source.</p>
</div>
<p>Built by <a href="https://davemaynard.dev">Dave Maynard</a></p>
</footer>
</main>
<script type="module">
import {AppearOnScroll} from '../dist/index.js';
const instances = [
new AppearOnScroll('[data-slide]', {duration: 900}),
new AppearOnScroll('[data-dir-up]', {direction: 'up'}),
new AppearOnScroll('[data-dir-down]', {direction: 'down'}),
new AppearOnScroll('[data-dir-left]', {direction: 'left', distance: '40px'}),
new AppearOnScroll('[data-dir-right]', {direction: 'right', distance: '40px'}),
new AppearOnScroll('[data-fade]', {animation: 'fade'}),
new AppearOnScroll('[data-zoom]', {animation: 'zoom', scale: 0.9}),
new AppearOnScroll('[data-blur]', {animation: 'blur'}),
new AppearOnScroll('.stagger-cell', {stagger: 90, duration: 500}),
new AppearOnScroll('[data-again]', {once: false}),
new AppearOnScroll('[data-once]', {once: true}),
];
// Test hook: lets the Playwright suite call destroy() on everything.
window.__aosInstances = instances;
document.querySelector('.tease').addEventListener('click', () => {
document.getElementById('slide').scrollIntoView({behavior: 'smooth', block: 'start'});
});
</script>
</body>
</html>