首先,看看下面的代码:
window.addEventListener('scroll', () => {
document.body.style.setProperty('--scroll', window.pageYOffset / (document.body.offsetHeight - window.innerHeight));
}, false);
.top-line {
width: 7px;
height: 100%;
position: absolute;
bottom: auto;
left: 0;
z-index: 2000;
background-color: #f00;
border-radius: 0;
animation: bottom-line 1s linear;
-webkit-animation: bottom-line 1s linear;
-moz-animation: bottom-line 1s linear;
-o-animation: bottom-line 1s linear;
-ms-animation: bottom-line 1s linear;
}
@keyframes bottom-line {
to {
background-color: #f00;
height: 0%;
}
}
:root .top-line {
animation-play-state: paused;
animation-delay: calc(var(--scroll) * -1s);
animation-iteration-count: 1;
animation-fill-mode: both;
}
<div class="top-line"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
正如您在上面的代码中看到的那样,左侧导航栏开始随着主页滚动而移动.但这种移动是错误的,因为左侧滚动条在主页滚动到达终点之前到达终点.
我希望左滚动条首先为0%(隐藏),然后当主滚动开始从上到下移动时,左滚动条以与主滚动相反的方向从下到上移动.