给大家分享一个用CSS 3.0实现时光轴加载动画,效果如下:
以下是代码实现,欢迎大家复制、粘贴和收藏。
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS 3.0实现时光轴加载动画</title>
<style>
html {
height: 100%;
background: linear-gradient(#813b97, #463c96);
}
@-webkit-keyframes progress1 {
0% {
transform: scalex(0);
opacity: 0.5;
}
90% {
transform: scalex(1);
opacity: 1;
}
92% {
transform: scalex(1);
opacity: 1;
}
100% {
transform: scalex(1);
opacity: 0;
}
}
@keyframes progress1 {
0% {
transform: scalex(0);
opacity: 0.5;
}
90% {
transform: scalex(1);
opacity: 1;
}
92% {
transform: scalex(1);
opacity: 1;
}
100% {
transform: scalex(1);
opacity: 0;
}
}
@-webkit-keyframes progress2 {
0% {
transform: scale(0.3, 0.8) translatez(0);
opacity: 0;
}
90% {
transform: scale(1, 1) translatex(300px) translatez(0);
opacity: 1;
}
100% {
transform: scale(1, 1) translatex(300px) translatez(0);
opacity: 0;
}
}
@keyframes progress2 {
0% {
transform: scale(0.3, 0.8) translatez(0);
opacity: 0;
}
90% {
transform: scale(1, 1) translatex(300px) translatez(0);
opacity: 1;
}
100% {
transform: scale(1, 1) translatex(300px) translatez(0);
opacity: 0;
}
}
.line {
position: absolute;
top: 50%;
width: 300px;
left: 50%;
margin-left: -150px;
height: 3px;
background: rgba(255, 255, 255, 0.1);
}
.line:before {
-webkit-animation: progress1 4s infinite;
animation: progress1 4s infinite;
transform-origin: 0 0;
content: "";
display: block;
width: 300px;
height: 100%;
background: linear-gradient(to right, rgba(255, 255, 255, 0.1) 10%, rgba(255, 255, 255, 0.4) 80%, white);
}
.line:after {
content: "";
position: absolute;
-webkit-animation: progress2 4s infinite;
animation: progress2 4s infinite;
transform-origin: 90% 50%;
margin-left: -24px;
top: -9px;
width: 30px;
height: 21px;
border-radius: 2px;
background: rgba(210, 189, 255, 0.55);
filter: blur(8px);
box-shadow: 0 0 10px 6px rgba(210, 189, 255, 0.4), -20px 0 15px 4px rgba(117, 75, 206, 0.3), -40px 0 15px 2px rgba(210, 189, 255, 0.2), -60px 0 10px 1px rgba(154, 130, 204, 0.1), -80px 0 10px 1px rgba(210, 189, 255, 0.05);
}
</style>
</head>
<body>
<div class="line"></div>
</body>
</html>