示例工程 36-scroll-animations
36-scroll-animations/demo-01-progress/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>滚动进度条</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>滚动进度条</h1>
<p>滚动下面的面板,顶部细条同步增长。</p>
<div class="panel">
<div class="bar" aria-hidden="true"></div>
<div class="content">
<p>第一段:滚动容器需要固定高度与 overflow。</p>
<p>第二段:给容器命名 scroll-timeline。</p>
<p>第三段:动画使用 animation-timeline。</p>
<p>第四段:进度由滚动位置驱动。</p>
<p>第五段:不需要 JS 监听 scroll。</p>
<p>第六段:接近底部。</p>
<p>第七段:到底了。</p>
</div>
</div>
</body>
</html>