👏渐变+伪元素实现流星,translateY实现划过动画,速速来Get吧~
🥇文末分享源代码。记得点赞+关注+收藏!

translateY():
translateY() 在页面垂直移动元素。
translateY(ty) 对应 translate(0, ty) 或translate3d(0, ty, 0)。
rotate():
rotate() 函数定义了一种将元素围绕一个定点(由transform-origin属性指定)旋转而不变形的转换。指定的角度定义了旋转的量度。若角度为正,则顺时针方向旋转,否则逆时针方向旋转。旋转 180° 也被称为点反射。

background-position:
CSS 属性为每一个背景图片设置初始位置。这个位置是相对于由 background-origin 定义的位置图层的。

width: 5px;
height: 85px;
background: linear-gradient(0deg, orange 0, red 100%);

background: linear-gradient(0deg, orange 0, transparent 100%);

content: "";
position: absolute;
width: 14px;
height: 14px;
border-radius: 50%;
background: orange;
filter: blur(1.8px);
bottom: -6px;
left: 50%;
transform: translate(-50%);

transform: rotate(45deg);

!!!注意:以下代码基于vue
lineList: [
{
c1: "#69E4F6",
c2: "#69e4f600",
l: "0px",
d: 3,
},
{
c1: "#FED258",
c2: "rgba(254,210,88,0)",
l: "60px",
d: 5,
},
{
c1: "#FED258",
c2: "rgba(254,210,88,0)",
r: "72px",
d: 2,
},
{
c1: "#69E4F6",
c2: "#69e4f600",
r: "30px",
d: 0,
},
{
c1: "#69E4F6",
c2: "#69e4f600",
r: "41px",
d: 1,
},
{
c1: "#69E4F6",
c2: "#69e4f600",
l: "105px",
d: 4,
},
{
c1: "#FED258",
c2: "rgba(254,210,88,0)",
l: "30px",
d: 2,
},
{
c1: "#FED258",
c2: "rgba(254,210,88,0)",
r: "111px",
d: 5,
},
{
c1: "#69E4F6",
c2: "#69e4f600",
r: "2px",
d: 3,
},
],
<div class="line-box">
<span
class="line-item"
v-for="(item,index) in lineList"
:key="index"
:style="{
'--c1':item.c1,
'--c2':item.c2,
'--l':item.l,
'--d':item.d,
'--r':item.r
}"
></span>
</div>
.line-item {
width: 2px;
height: 33px;
background: linear-gradient(0deg, var(--c1) 0%, var(--c2) 100%);
position: absolute;
top: 0;
transform: rotate(45deg);
left: var(--l);
right: var(--r);
}
.line-item::after {
content: "";
position: absolute;
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--c1);
filter: blur(1.8px);
box-shadow: 0px -1px -1px 5px var(--c2);
bottom: -4px;
left: 50%;
transform: translate(-50%);
}

.line-item{
+ opacity: 0;
}

@keyframes shank {
0% {
transform: rotate(45deg) translateY(-100px) scale(0.5);
opacity: 0;
}
70% {
opacity: 1;
transform: rotate(45deg) translateY(100px) scale(1.1);
}
100% {
transform: rotate(45deg) translateY(220px) scale(0.5);
opacity: 0;
}
}
.line-item{
+ animation: shank 2s linear infinite;
+ animation-delay: calc(var(--d) * 0.2s);
}

.line-item{
- left: var(--l);
- right: var(--r);
+ left: calc(var(--l) + 70px);
+ right: calc(var(--r) - 70px);
}

.container::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: url(./img/earth.jpg) no-repeat;
background-size: cover;
animation: ping 4s infinite linear alternate-reverse;
}
@keyframes ping {
100% {
background-position: 100%;
}
}
.container {
box-shadow: 0px 2px 12px rgba(0, 0, 0, 0.2);
border-radius: 20px;
padding: 40px;
position: relative;
width: 350px;
height: 260px;
overflow: hidden;
}
.container::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: url(./img/earth.jpg) no-repeat;
background-size: cover;
animation: ping 4s infinite linear alternate-reverse;
}
@keyframes ping {
100% {
background-position: 100%;
}
}
.line-box {
width: 100%;
height: 100%;
position: relative;
}
.line-item {
width: 2px;
height: 33px;
background: linear-gradient(0deg, var(--c1) 0%, var(--c2) 100%);
position: absolute;
top: 0;
transform: rotate(45deg);
left: calc(var(--l) + 70px);
right: calc(var(--r) - 70px);
opacity: 0;
animation: shank 2s linear infinite;
animation-delay: calc(var(--d) * 0.2s);
}
.line-item::after {
content: "";
position: absolute;
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--c1);
filter: blur(1.8px);
box-shadow: 0px -1px -1px 5px var(--c2);
bottom: -4px;
left: 50%;
transform: translate(-50%);
}
@keyframes shank {
0% {
transform: rotate(45deg) translateY(-100px) scale(0.5);
opacity: 0;
}
70% {
opacity: 1;
transform: rotate(45deg) translateY(100px) scale(1.1);
}
100% {
transform: rotate(45deg) translateY(220px) scale(0.5);
opacity: 0;
}
}
<div class="container" >
<div class="line-box">
<span
class="line-item"
v-for="(item,index) in lineList"
:key="index"
:style="{
'--c1':item.c1,
'--c2':item.c2,
'--w':item.w,
'--h':item.h,
'--l':item.l,
'--d':item.d,
'--r':item.r
}"
></span>
</div>
</div>