-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreading-progress.html
More file actions
86 lines (78 loc) · 3.18 KB
/
Copy pathreading-progress.html
File metadata and controls
86 lines (78 loc) · 3.18 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>scroll-anim-fallback — reading progress bar</title>
<script>
(function () {
var forced = new URLSearchParams(location.search).get('forceFallback') === '1';
document.write('<link rel="stylesheet" href="dist/reading-progress' + (forced ? '.forced' : '') + '.css">');
}());
</script>
<style>
:root { color-scheme: light dark; --ink: #14161a; --paper: #fbfaf7; }
@media (prefers-color-scheme: dark) { :root { --ink: #eceff4; --paper: #14161a; } }
* { box-sizing: border-box; }
body {
margin: 0; padding: 0 1.5rem 8rem;
background: var(--paper); color: var(--ink);
font: 16px/1.6 system-ui, sans-serif;
}
.prose { max-width: 42rem; margin: 0 auto; padding-top: 4rem; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); margin: 0 0 .5rem; letter-spacing: -0.02em; }
p { margin: 0 0 1rem; opacity: .8; }
.badge {
display: inline-block; font: 600 12px/1 ui-monospace, monospace;
padding: .5em .75em; border-radius: 999px; border: 1px solid currentColor;
}
.reading-progress {
position: fixed; inset: 0 0 auto; height: 5px; z-index: 10;
background: color-mix(in srgb, var(--ink) 12%, transparent);
}
/* `transform-origin` lives here, not in the animated stylesheet: the plugin
moves every declaration of the matched rule inside the @supports guard. */
.reading-progress__bar {
height: 100%;
transform-origin: 0 50%;
background: linear-gradient(90deg, #2b6cb0, #6b46c1);
}
</style>
</head>
<body>
<div class="reading-progress"><div class="reading-progress__bar"></div></div>
<div class="prose">
<h1>Reading progress bar</h1>
<p>
A <code>scroll(root block)</code> timeline. Native support maps the document
scroller's full range onto the animation; the fallback computes the same
thing from <code>scrollTop / (scrollHeight - clientHeight)</code>.
</p>
<p><span class="badge" id="status">detecting…</span></p>
<p><a href="?forceFallback=1">Force the fallback path</a> · <a href="./">Back to the demo index</a></p>
<div id="filler"></div>
</div>
<script src="../packages/scroll-anim-fallback-runtime/dist/scroll-anim-fallback.umd.js"></script>
<script src="dist/reading-progress.manifest.js"></script>
<script>
// Generate enough copy to scroll through.
var filler = document.getElementById('filler');
for (var i = 1; i <= 40; i++) {
var p = document.createElement('p');
p.textContent = 'Paragraph ' + i + '. Scroll-driven animations tie an animation’s ' +
'progress to a scroll position rather than to elapsed time, which is why a ' +
'time-based fallback has to be seeked rather than played.';
filler.appendChild(p);
}
var forced = new URLSearchParams(location.search).get('forceFallback') === '1';
var activated = ScrollAnimFallback.init({
manifest: window.SAF_MANIFEST,
reducedMotion: 'ignore', // a progress indicator is not decorative motion
force: forced
});
document.getElementById('status').textContent = activated
? (forced ? 'fallback runtime (forced)' : 'fallback runtime')
: 'native animation-timeline';
</script>
</body>
</html>