|
|
|
|
|
本文介紹一個流星雨效果的動畫背景,它是純CSS實現(xiàn)的,無需用到JavaScript,也無需用到第三方插件,喜歡的朋友可以直接復(fù)制代碼使用,非常方便。
實例分析
<div class="night">
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
<div class="shooting_star"></div>
</div>
一共有20個<div class="shooting_star"></div>
,一個shooting_star
的div代表一顆流星。
.shooting_star {
position: absolute;
left: 50%;
top: 50%;
height: 2px;
background: linear-gradient(-45deg, #5f91ff, rgba(0, 0, 255, 0));
border-radius: 999px;
filter: drop-shadow(0 0 6px #699bff);
-webkit-animation: tail 3000ms ease-in-out infinite, shooting 3000ms ease-in-out infinite;
animation: tail 3000ms ease-in-out infinite, shooting 3000ms ease-in-out infinite;
}
.shooting_star::before {
content: "";
position: absolute;
top: calc(50% - 1px);
right: 0;
height: 2px;
background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
transform: translateX(50%) rotateZ(45deg);
border-radius: 100%;
-webkit-animation: shining 3000ms ease-in-out infinite;
animation: shining 3000ms ease-in-out infinite;
}
.shooting_star::after {
content: "";
position: absolute;
top: calc(50% - 1px);
right: 0;
height: 2px;
background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
transform: translateX(50%) rotateZ(45deg);
border-radius: 100%;
-webkit-animation: shining 3000ms ease-in-out infinite;
animation: shining 3000ms ease-in-out infinite;
transform: translateX(50%) rotateZ(-45deg);
}
每個流星出現(xiàn)的延遲時間,CSS:
.shooting_star:nth-child(1) {
top: calc(50% - -4px);
left: calc(50% - 248px);
-webkit-animation-delay: 3060ms;
animation-delay: 3060ms;
}
.shooting_star:nth-child(1)::before, .shooting_star:nth-child(1)::after {
-webkit-animation-delay: 3060ms;
animation-delay: 3060ms;
}
從nth-child(1)
到nth-child(20)
,animation-delay
的值不同。
總結(jié)
本文介紹一個流星雨效果的動畫背景,它是純CSS實現(xiàn)的,無需用到JavaScript,也無需用到第三方插件,喜歡的朋友可以直接復(fù)制代碼使用,非常方便。