渡一教育公开课web前端开发JavaScript精英课学习笔记(二十一)CSS3实现Loading
CSS3实现Loading
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
background: #333333;
}
.demo {
position: absolute;
top: 50px;
left: 40%;
width: 200px;
height: 200px;
border: 1px solid #ffffff;
margin: 150 auto;
display: flex;
justify-content: center;
align-items: center;
}
.demo .shape {
position: relative;
width: 10px;
height: 10px;
display: inline-block;
border: 1px solid #ffffff;
margin: 0 5px;
opacity: 0.5;
}
.demo .shape1 {
background-color: blue;
animation: animation1 1s ease infinite 0.0s;
}
.demo .shape2 {
background-color: red;
animation: animation1 1s ease infinite 0.25s;
}
.demo .shape3 {
background-color: green;
animation: animation1 1s ease infinite 0.5s;
}
.demo .shape4 {
background-color: yellow;
animation: animation1 1s ease infinite 0.75s;
}
/* 设置关键帧动画 0% ~ 100%*/
@keyframes animation1 {
0% {
transform: scale(1);
opcaity: 0.5;
}
50% {
transform: scale(1.5);
opcaity: 1;
}
100% {
transform: scale(1);
opcaity: 0.5;
}
}
.demo2 {
position: absolute;
top: 300px;
left: 40%;
width: 200px;
height: 200px;
border: 1px solid #ffffff;
margin: 150 auto;
display: flex;
justify-content: center;
align-items: center;
}
.con {
position:absolute;
width: 40px;
height: 40px;
/* border: 1px solid #ffffff; */
}
.ball {
position:absolute;
top:40%;
display: inline-block;
width: 10px;
height: 10px;
background-color: #ffffff;
border-radius: 50%;
}
.ball1{
left:0px;
animation: animation2 1s ease infinite 0s;
background-color:blue;
}
.ball2{
left:10px;
background-color:red;
}
.ball3{
left:20px;
background-color:green;
}
.ball4{
left:30px;
animation: animation3 1s ease infinite 0.5s;
background-color:yellow;
}
@keyframes animation2{
0%{
left:0px;
top:40%;
}
25%{
left:-20px;
top:00%;
}
50%{
left:0px;
top:40%;
}
75%{
left:0px;
top:40%;
}
100%{
left:0px;
top:40%;
}
}
@keyframes animation3{
0%{
left:30px;
top:40%;
}
25%{
left:50px;
top:0%;
}
50%{
left:30px;
top:40%;
}
75%{
left:30px;
top:40%;
}
100%{
left:30px;
top:40%;
}
}
</style>
</head>
<body>
<div class="demo">
<div class="shape shape1"></div>
<div class="shape shape2"></div>
<div class="shape shape3"></div>
<div class="shape shape4"></div>
</div>
<div class="demo2">
<div class="con">
<div class="ball ball1"></div>
<div class="ball ball2"></div>
<div class="ball ball3"></div>
<div class="ball ball4"></div>
</div>
</div>
</body>
</html>