例如,我有一个高度很高的网页,它有一个通常在滚动时起床的加载程序。但是,我希望那个装载机始终保持在中心位置,尽管滚动位置。我怎样才能做到这一点?如何修复可滚动页面中心的元素?
HTML
<div class="loader"></div>
CSS
body {
height: 1000vh;
margin: 0;
}
.loader:before,
.loader:after,
.loader {
border-radius: 50%;
width: 2.5em;
height: 2.5em;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation: load7 1.8s infinite ease-in-out;
animation: load7 1.8s infinite ease-in-out;
}
.loader {
font-size: 10px;
margin: 80px auto;
position: relative;
text-indent: -9999em;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
.loader:before {
left: -3.5em;
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.loader:after {
left: 3.5em;
}
.loader:before,
.loader:after {
content: '';
position: absolute;
top: 0;
}
@-webkit-keyframes load7 {
0%,
80%,
100% {
box-shadow: 0 2.5em 0 -1.3em #C74038;
}
40% {
box-shadow: 0 2.5em 0 0 #C74038;
}
}
@keyframes load7 {
0%,
80%,
100% {
box-shadow: 0 2.5em 0 -1.3em #C74038;
}
40% {
box-shadow: 0 2.5em 0 0 #C74038;
}
}
我确定它只是一个复制粘贴错误,但你仍然有'位置:相对',正在被'position:fixed'覆盖。 – AtheistP3ace
是啊,你说得对,我忽略了“立场:亲戚”,但它应该仍然有效,因为后者的规则是优先的。虽然修正了它。 –
是的,它仍然适用于它! =] – AtheistP3ace