效果圖

lyxg.gif
代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>漣漪動畫效果</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
width: 800px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: #111;
}
.container .box {
width: 300px;
height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.container .box span {
position: absolute;
border: 2px solid #fff;
box-sizing: border-box;
border-radius: 50%;
animation: animate 5s linear infinite;
animation-delay: calc(0.5s * var(--i));
}
.container .box:nth-child(2) span {
border: none;
background: rgba(0, 255, 0, 0.25);
}
@keyframes animate {
0% {
width: 0;
height: 0;
}
50% {
opacity: 1;
}
100% {
width: 300px;
height: 300px;
opacity: 0;
}
}
</style>
</head>
<body>
<div class="container">
<div class="box">
<span style="--i:1"></span>
<span style="--i:2"></span>
<span style="--i:3"></span>
<span style="--i:4"></span>
<span style="--i:5"></span>
<span style="--i:6"></span>
<span style="--i:7"></span>
<span style="--i:8"></span>
<span style="--i:9"></span>
<span style="--i:10"></span>
</div>
<div class="box">
<span style="--i:1"></span>
<span style="--i:2"></span>
<span style="--i:3"></span>
<span style="--i:4"></span>
<span style="--i:5"></span>
<span style="--i:6"></span>
<span style="--i:7"></span>
<span style="--i:8"></span>
<span style="--i:9"></span>
<span style="--i:10"></span>
</div>
</div>
</body>
</html>
知識點(diǎn):
animation屬性是一個簡寫屬性,用于設(shè)置六個動畫屬性
語法:
animation:name|動畫名稱 duration|完成動畫所需時間 timing-function|速度曲線 delay|開始前延遲時間 iteration-count|播放次數(shù) direction|是否反向播放;
1、animation-name:@keyframe動畫規(guī)定的名稱;(必須)
2、animation-duration:完成動畫所花費(fèi)的時間,以秒或者毫秒計(jì);(必須,否則不會播放動畫,默認(rèn)是0,表示無動畫)
3、animation-timing-function:規(guī)定動畫的速度曲線;(默認(rèn)ease)
linear:勻速播放動畫;
ease:默認(rèn),低速開始,然后加快,在結(jié)束前再變慢(慢-快-慢);
ease-in:低速開始;
ease-out:低速結(jié)束;
ease-in-out:以低速開始和結(jié)束;
cubic-bezier(n,n,n,n):在 cubic-bezier 函數(shù)中設(shè)置自己的值??赡艿闹凳菑?0 到 1 的數(shù)值。
4、animation-delay:規(guī)定在動畫開始之前的延遲,默認(rèn)值是0,表示不延遲,立即播放動畫。單位是s或者ms毫秒。允許設(shè)置負(fù)時間,意思是讓動畫動作從該時間點(diǎn)開始啟動,之前的動畫不顯示;例如-2s使動畫馬上開始,但前2秒的動畫被跳過;
5、animation-iteration-count:規(guī)定動畫應(yīng)該播放的次數(shù);默認(rèn)值為1,播放完一遍后不循環(huán)播放。(n:播放次數(shù)數(shù)值;infinite:無限次播放)
6、animation-direction:規(guī)定是否應(yīng)該輪流反向播放動畫;(normal:默認(rèn)值,正常播放;alternate:輪流反向播放|奇數(shù)次正向播放,偶數(shù)次反向播放,alternate-reverse:輪流反向播放|奇數(shù)次反向播放動畫,偶數(shù)次正向播放動畫,和alternate正好相反。)
animation-fill-mode:設(shè)置動畫結(jié)束時,盒子的狀態(tài)。屬性值:forwards:保持動畫結(jié)束后的狀態(tài)(默認(rèn));backwards:動畫結(jié)束后回到最初的狀態(tài);
通過 @keyframes 規(guī)則,您能夠創(chuàng)建動畫
語法:
@keyframes animationname {keyframes-selector {css-styles;}}
animationname---必需。定義動畫的名稱。
keyframes-selector---必需。動畫時長的百分比。
合法的值:
0-100%
from(與 0% 相同)
to(與 100% 相同)
css-styles----必需。一個或多個合法的 CSS 樣式屬性。