-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
421 lines (385 loc) · 14.6 KB
/
index.html
File metadata and controls
421 lines (385 loc) · 14.6 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Scroll Progress Bar – Puce CSS (No JavaScript) | MobiWise.dev</title>
<!-- Primary SEO -->
<meta name="description" content="CSS-only scroll progress bar using scroll-driven animations, typed custom properties (CSS Houdini), and CSS counters. No JavaScript required." />
<link rel="canonical" href="https://mobiwise-dev.github.io/NoJsScrollBar/" />
<!-- Open Graph / Social preview -->
<meta property="og:type" content="website" />
<meta property="og:title" content="CSS-Only Scroll Progress Bar (No JavaScript)" />
<meta property="og:description" content="Experimental CSS demo using scroll-driven animations and typed custom properties to build a scroll progress bar without JavaScript." />
<meta property="og:url" content="https://mobiwise-dev.github.io/NoJsScrollBar/" />
<meta property="og:site_name" content="MobiWise.dev" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="CSS-Only Scroll Progress Bar" />
<meta name="twitter:description" content="Scroll-driven animations + CSS Houdini = progress bar without JavaScript." />
<!-- Favicon (minimal, optional but recommended) -->
<link rel="icon" href="https://mobiwise.dev/MobiWise_Logo-Square.svg" />
<style>
@layer reset, base, components, utilities;
@property --scroll {
syntax: "<number>";
inherits: false;
initial-value: 0;
}
#progress-bar {
position: fixed;
inset: 0 0 auto 0;
z-index: 1000;
height: 0.33rem;
background: linear-gradient(to right, blue calc(var(--scroll) * 1%), transparent 0);
}
#scroll-indicator {
position: fixed;
top: 2rem;
right: 2rem;
padding: 0.6rem 1rem;
font-size: 1rem;
color: white;
border-radius: 1.4rem;
background: rgba(0, 0, 0, 0.8);
&::before {
content: counter(scroll-value) "%";
counter-reset: scroll-value calc(var(--scroll));
}
}
#progress-bar,
#scroll-indicator::before {
animation: scroll-progress linear both;
animation-timeline: scroll(root);
}
@layer utilities {
@supports not (animation-timeline: scroll(root)) {
body:before {
content: "😬 Sorry Firefox users, this doesn't work for you.";
font-size: 25px;
min-height: 100dvh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#progress-bar,
#scroll-indicator {
display: none;
}
section {
display: none;
}
}
}
@keyframes scroll-progress {
from {
--scroll: 0;
}
to {
--scroll: 100;
}
}
@layer reset {
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
}
@layer base {
@property --bg-color {
syntax: "<color>";
inherits: false;
initial-value: oklch(0.21 0.03 265);
}
@property --grid-color {
syntax: "<color>";
inherits: false;
initial-value: oklch(1 0 0 / 0.05);
}
@property --color {
syntax: "<color>";
inherits: false;
initial-value: oklch(0.87 0.12 81);
}
body {
min-height: 100dvh;
font-family: Arial, sans-serif;
font-size: 1.5rem;
color: oklch(from var(--bg-color) 0.8 c h);
background-color: var(--bg-color);
background-image:
linear-gradient(var(--grid-color) 1px, transparent 1px), linear-gradient(90deg, var(--grid-color) 1px, transparent 1px), linear-gradient(var(--grid-color) 2px, transparent 2px),
linear-gradient(90deg, var(--grid-color) 2px, transparent 2px);
background-size:
10px 10px,
10px 10px,
100px 100px,
100px 100px;
}
h1 {
font-size: 4rem;
font-weight: 900;
text-align: center;
color: white;
& span {
font-size: clamp(2rem, 15vw, 8rem);
color: var(--color);
-webkit-text-stroke: 1px white;
text-shadow: 0.25rem -0.25rem 0.375rem oklch(from var(--bg-color) l c h / 0.1);
&:hover {
text-decoration: line-through;
}
}
}
h2 {
font-size: 3rem;
text-align: center;
color: white;
margin-bottom: 1rem;
}
p {
margin: 1rem 0;
}
b {
color: white;
}
code {
color: white;
background-color: black;
}
main {
max-width: 50rem;
margin: 0 auto;
}
section {
min-height: 100vh;
padding: 2rem 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
footer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
p {
display: inline-block;
font-size: 0.8rem;
text-align: center;
a {
color: inherit;
text-decoration: none;
&:hover {
color: white;
}
}
}
}
}
@layer components {
#logo {
position: fixed;
top: 2rem;
left: 2rem;
height: 6vh;
aspect-ratio: 0.587;
background-color: oklch(from var(--bg-color) 0.8 c h);
clip-path: shape(
from 97.41% 41.31%,
arc by 2.59% 1.52% of 2.59% 1.52% small cw,
vline by 55.65%,
curve by -4.42% 1.08% with 0% 1.35%/-2.79% 2.03%,
line to 0.76% 43.9%,
curve to 2.6% 41.31% with -0.87% 42.95%/0.29% 41.31%,
hline to 97.41%,
close,
move to 45.6% 74.32%,
curve by 4.42% 1.08% with 1.63% -0.96%/4.42% -0.28%,
vline to 87.59%,
arc by -2.59% 1.52% of 2.59% 1.52% small cw,
hline to 26.66%,
curve by -1.83% -2.6% with -2.31% 0%/-3.47% -1.64%,
line by 20.77% -12.19%,
close,
move to 90.02% 0.45%,
curve by 4.42% 1.08% with 1.63% -0.96%/4.42% -0.28%,
vline by 8.73%,
arc by -0.76% 1.08% of 2.59% 1.52% small cw,
line by -41.83% 24.55%,
arc by -3.66% 0% of 2.59% 1.52% small cw,
line by -41.83% -24.55%,
arc to 5.6% 10.26% of -6.62% -4.97% small cw,
vline to 1.52%,
curve by 4.42% -1.08% with 0% -1.36%/2.79% -2.03%,
line by 17.03% 10%,
arc by 1.83% 0.45% of 2.59% 1.52% small ccw,
hline by 42.28%,
arc by 1.83% -0.45% of 2.59% 1.52% small ccw,
line by 17.03% -10%,
close,
move to 13% 23.25%,
curve by 4.42% -1.08% with 0% -1.35%/2.79% -2.03%,
line by 13.36% 7.84%,
curve by -1.83% 2.6% with 1.63% 0.96%/0.48% 2.6%,
hline by -13.36%,
arc by -2.59% -1.52% of 2.59% 1.52% small cw,
vline by -7.84%,
close,
move to 82.62% 22.18%,
curve by 4.42% 1.08% with 1.63% -0.96%/4.42% -0.28%,
vline to 31.1%,
arc by -2.59% 1.52% of 2.59% 1.52% small cw,
hline by -13.37%,
curve by -1.83% -2.6% with -2.31% 0%/-3.46% -1.64%,
line by 13.37% -7.84%,
close
);
transition: 0.3s;
&:hover {
transform: scale(1.1);
background-color: oklch(1 0 0);
}
}
#github {
position: fixed;
left: 2rem;
bottom: 2rem;
padding: 0.6rem;
gap: 1rem;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
font-size: 1rem;
color: oklch(1 0 0);
text-decoration: none;
border-radius: 2rem;
background: oklch(0 0 0);
transition: 0.3s;
&:hover {
transform: scale(1.1);
background: oklch(0.2 0 0);
}
span {
height: 1.5rem;
width: 1.5rem;
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='black' d='M12 .297c-6.63 0-12 5.373-12 12c0 5.303 3.438 9.8 8.205 11.385c.6.113.82-.258.82-.577c0-.285-.01-1.04-.015-2.04c-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729c1.205.084 1.838 1.236 1.838 1.236c1.07 1.835 2.809 1.305 3.495.998c.108-.776.417-1.305.76-1.605c-2.665-.3-5.466-1.332-5.466-5.93c0-1.31.465-2.38 1.235-3.22c-.135-.303-.54-1.523.105-3.176c0 0 1.005-.322 3.3 1.23c.96-.267 1.98-.399 3-.405c1.02.006 2.04.138 3 .405c2.28-1.552 3.285-1.23 3.285-1.23c.645 1.653.24 2.873.12 3.176c.765.84 1.23 1.91 1.23 3.22c0 4.61-2.805 5.625-5.475 5.92c.42.36.81 1.096.81 2.22c0 1.606-.015 2.896-.015 3.286c0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12'/%3E%3C/svg%3E")
no-repeat;
mask-size: 100% 100%;
background-color: oklch(1 0 0);
}
}
#mouse {
position: fixed;
bottom: 5vh;
right: 5vh;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.7rem;
.mouse-scroll {
position: relative;
width: 1.5rem;
height: 2.5rem;
border: 0.15rem solid white;
border-radius: 2rem;
&::before {
content: "";
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 0.4em;
height: 0.4em;
border-radius: 50%;
background: white;
animation: scroller 1.5s infinite;
}
}
p {
margin: 0 0.6rem;
text-align: right;
}
}
@keyframes scroller {
0% {
bottom: 80%;
opacity: 1;
}
100% {
bottom: 50%;
opacity: 0;
}
}
}
</style>
</head>
<body>
<div id="progress-bar"></div>
<div id="scroll-indicator"></div>
<div id="mouse">
<p>Scroll down<br />to see<br />the magic</p>
<div class="mouse-scroll"></div>
</div>
<a id="logo" href="https://mobiwise.dev" target="_blank" rel="author" title="visit mobiwise.dev" aria-label="link to mobiwise.dev" data-text="MobiWise.dev"></a>
<a id="github" href="https://github.com/mobiwise-dev/NoJsScrollBar" target="_blank" title="more info on GitHUb" aria-label="link to GitHub" data-text="MobiWise.dev"><span></span> More info on GitHub</a>
<main>
<section>
<h1>Scroll Progress Bar without <span data-depth="1.5rem" data-depth-layers="20" data-depth-event="pointer" data-depth-event-rotation="15deg">JavaScript</span></h1>
</section>
<section>
<h2>Scroll Progress Bar - CSS only (with scroll-driven animations)</h2>
<p>This demo shows how to build a scroll progress bar entirely in CSS, using scroll-driven animations <code>animation-timeline: scroll()</code>, custom properties, and no JavaScript for the progress itself.</p>
<p>The progress bar at the top of the page is driven by a CSS custom property <code>--scroll</code> that animates from <code>0</code> to <code>100</code> as the document scrolls.</p>
<p>This value is then reused to dynamically update the bar’s gradient; all handled by the browser’s animation engine.</p>
</section>
<section>
<h2>What’s CSS-only here</h2>
<ul>
<li>Scroll position tracking via <code>animation-timeline: scroll(root)</code></li>
<li>Progress calculation using a typed custom property <code>@property</code></li>
<li>Smooth, performant updates handled natively by CSS</li>
<li>No JavaScript involved in computing or animating the progress bar</li>
</ul>
</section>
<section>
<h2>About the percentage counter</h2>
<p>Displaying a live numeric value in pure CSS has long been considered difficult, especially when the value is driven by animations.</p>
<p>
This demo uses a modern CSS approach combining typed custom properties
<code>@property</code> and CSS counters to display the scroll percentage without JavaScript.
</p>
<ul>
<li>The scroll position animates a numeric CSS variable <code>--scroll</code></li>
<li>The variable is typed and interpolated using CSS Houdini</li>
<li>A CSS counter converts the numeric value into readable text</li>
<li>The displayed value is an integer approximation (0–100)</li>
</ul>
<p>This technique relies on very recent CSS features and is currently supported only in modern Chromium-based browsers and Safari.</p>
<p>
<b> In production environments, JavaScript is still the most robust solution for dynamic numeric text — but this demo shows what modern CSS can already do. </b>
</p>
</section>
<section>
<h2>Takeaway</h2>
<ul>
<li>Modern CSS can track scroll position without JavaScript</li>
<li>Typed custom properties enable real numeric interpolation</li>
<li>CSS counters can expose animated values as readable text</li>
<li>JavaScript remains the best choice for full cross-browser support</li>
</ul>
<p>This pen explores the current frontier of what CSS can do today, without polyfills, hacks, or misleading shortcuts.</p>
</section>
<footer>
<p>
© 2026
<a class="link" href="https://mobiwise.dev" target="_blank" rel="author" title="visit mobiwise.dev" aria-label="link to mobiwise.dev" data-text="MobiWise.dev">MobiWise.dev</a>
</p>
</footer>
</main>
<script src="https://cdn.jsdelivr.net/npm/depthtext@1.2.0/dist/depthtext.global.js"></script>
</body>
</html>