分析需求

如何得知用户当前滚动页面的距离并且通知顶部进度条?

如此思考则陷入了传统思维,进度条就是进度条,接收页面滚动距离,改变宽度。如果页面滚动和进度条是一个整体呢。

实现需求

线性渐变
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
.scroll{
margin: 1rem 0;
height: 20rem;
border: 1px dashed #cdcdcd;
overflow: auto;
}
.wrap{
margin-top: 8px;
padding: 1rem;
position: relative;
}
.wrap blockquote,.wrap figure.highlight{
margin: 0!important;
padding: 0;
}
.wrap blockquote p {
padding-left: 1rem;
}
.wrap figure.highlight,.wrap pre{
background: transparent!important
}
.wrap::after {
content: "";
position: fixed;
top: 3.15rem;
left: 0;
width: 100%;
height: calc(20rem - .5rem);
background: #fff;
z-index: -1;
}
.wrap::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(to right top, #ffcc00 50%, #eee 50%);
background-size: calc(100% + 5px) calc(100% - 20.2rem + 8px);
background-repeat: no-repeat;
z-index: -2;
}