css动画实现页面loading加载
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>loading</title>
<style type="text/css">
.loadding-box{
position: relative;
width: 100px;
height: 100px;
background-color: rgba(0,0,0,0.8);
margin: 100px auto;
border-radius: 10px;
color: #fff;
overflow: hidden; /* 解决margin塌陷 */
}
.text{
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
}
.loadding{
width: 40px;
height: 40px;
margin: 10px auto; /* margin塌陷,bfc解决这个问题 */
position: relative;
}
.container1,.container2{
position: absolute;
width: 100%;
height: 100%;
}
.container2{
transform: rotate(45deg);
}
.circle{
width: 10px;
height: 10px;
border-radius: 5px;
background-color: #fff;
position:absolute;
animation: load 1.8s both infinite;
}
@keyframes load{
0%{
transform: scale(0); /* scale代表缩放 0和1代表缩放比例 */
}
40%{
transform: scale(1);
}
800%{
transform: scale(0);
}
100%{
transform: scale(0);
}
}
.circle:nth-child(1){
left: 0;
top: 0;
}
.container1 .circle:nth-child(1){
animation-delay: 0s;
}
.container2 .circle:nth-child(1){
animation-delay: 0.2s;
}
.circle:nth-child(2){
right: 0;
top: 0;
}
.container1 .circle:nth-child(2){
animation-delay: 0.4s;
}
.container2 .circle:nth-child(2){
animation-delay: 0.6s;
}
.circle:nth-child(3){
right: 0;
bottom: 0;
}
.container1 .circle:nth-child(3){
animation-delay: 0.8s;
}
.container2 .circle:nth-child(3){
animation-delay: 1.0s;
}
.circle:nth-child(4){
left: 0;
bottom: 0;
}
.container1 .circle:nth-child(4){
animation-delay: 1.2s;
}
.container2 .circle:nth-child(4){
animation-delay: 1.4s;
}
</style>
</head>
<body>
<div class="loadding-box">
<div class="loadding">
<div class="container1"> <!-- 两个矩形旋转 四个小球站在四个角 -->
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
<div class="container2">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
</div>
<p class="text">loadding...</p>
</div>
</body>
</html>