效果图:
index.html
<!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;
font-family: '微软雅黑';
}
.blwb {
margin: 100px auto;
width:30%;
min-height: 200px;
background: #000;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.blwb span {
position: relative;
color: #fff;
font-size: 18px;
animation: animate 1s ease-in-out infinite;
animation-delay: calc(.1s*var(--i));
}
@keyframes animate {
0% {
transform: translateY(0px);
}
20% {
transform: translateY(-24px);
}
40%,
100% {
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="blwb">
<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>
</div>
</body>
</html>
知识点:
animation属性是一个简写属性,用于设置六个动画属性
语法:
animation:name|动画名称 duration|完成动画所需时间 timing-function|速度曲线 delay|开始前延迟时间 iteration-count|播放次数 direction|是否反向播放;
1、animation-name:@keyframe动画规定的名称;(必须)
2、animation-duration:完成动画所花费的时间,以秒或者毫秒计;(必须,否则不会播放动画,默认是0,表示无动画)
3、animation-timing-function:规定动画的速度曲线;(默认ease)
linear:匀速播放动画;
ease:默认,低速开始,然后加快,在结束前再变慢(慢-快-慢);
ease-in:低速开始;
ease-out:低速结束;
ease-in-out:以低速开始和结束;
cubic-bezier(n,n,n,n):在 cubic-bezier 函数中设置自己的值。可能的值是从 0 到 1 的数值。
4、animation-delay:规定在动画开始之前的延迟,默认值是0,表示不延迟,立即播放动画。单位是s或者ms毫秒。允许设置负时间,意思是让动画动作从该时间点开始启动,之前的动画不显示;例如-2s使动画马上开始,但前2秒的动画被跳过;
5、animation-iteration-count:规定动画应该播放的次数;默认值为1,播放完一遍后不循环播放。(n:播放次数数值;infinite:无限次播放)
6、animation-direction:规定是否应该轮流反向播放动画;(normal:默认值,正常播放;alternate:轮流反向播放|奇数次正向播放,偶数次反向播放,alternate-reverse:轮流反向播放|奇数次反向播放动画,偶数次正向播放动画,和alternate正好相反。)
animation-fill-mode:设置动画结束时,盒子的状态。属性值:forwards:保持动画结束后的状态(默认);backwards:动画结束后回到最初的状态;
通过 @keyframes 规则,您能够创建动画
语法:
@keyframes animationname {keyframes-selector {css-styles;}}
animationname---必需。定义动画的名称。
keyframes-selector---必需。动画时长的百分比。
合法的值:
0-100%
from(与 0% 相同)
to(与 100% 相同)
css-styles----必需。一个或多个合法的 CSS 样式属性。