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">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section><span></span></section>
</body>
</html>
CSS
html,body{
margin: 0;
height: 100%;
}
body{
display: flex;
justify-content: center;
align-items: center;
background: #263238;
}
section {
width: 650px;
height: 300px;
padding: 10px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid red;
}
span {
width : 96px;
height: 96px;
position: relative;
}
span::before,
span::after{
position: absolute;
content: '';
width: 96px;
height: 96px;
top: 0;
left: 0;
background: white;
border-radius: 50%;
animation: animloader 4s ease-in-out infinite;
}
span::after{
animation-delay: 2s;
}
@keyframes animloader {
0% , 100%{ transform: scale(0); opacity: 1;}
50% { transform: scale(1); opacity: 0;}
}
使用span标签,设置为
width: 96px;
height: 96px;
position: relative;
利用span::before、span::after伪类元素作为白色圆圈部分
设置为
position: absolute;
content: '';
width: 96px;
height: 96px;
top: 0;
left: 0;
background: white;
效果图如下
span::before、span::after圆角化
border-radius: 50%;
效果图如下
为span::before、span::after添加动画
有三种状态
变换过程
animation: animloader 4s ease-in-out infinite;
@keyframes animloader {
0%, 100% {
transform: scale(0);
opacity: 1;
}
50% {
transform: scale(1);
opacity: 0;
}
}
效果图如下
从步骤4效果图可以看出
只有一个白色圆圈
而其实我们是设置了两个(一个before,一个after)
为了视觉上显示两个白色圆圈
我们对after进行动画延时
这样同一时刻就可以看到两个白色圆圈啦
animation-delay: 2s;
效果图如下