css3-loading动画
1.源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 800px;
background-color: #db4d6d;
display: flex; /*设置弹性盒模型*/
justify-content: center; /*设置水平居中*/
align-items: center; /*设置垂直居中*/
font-family: "微软雅黑";
}
.monster{
width: 110px;
height: 100px;
background-color: #e55a54;
border-radius: 20px;
margin-left: 10px;
position: relative;
display: flex; /*使内部元素水平垂直居中,且按行排列*/
justify-content: center;
align-items: center;
flex-direction: column;
animation: jumping 0.8s infinite alternate; /*设置运动动画*/
box-shadow: 0px 10px 20px rgba(0,0,0,0.5); /*设置阴影*/
}
.monster .eye{
width: 40%;
height: 40%;
margin: 10px;
border-radius: 50%;
background-color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.monster .mouth{
width: 32%;
height: 12px;
border-radius: 12px;
background-color: #fff;
}
.monster .eye .eyeball{
width: 50%;
height: 50%;
border-radius: 50%;
background-color: #0c4475;
animation: run 1.6s infinite alternate;
}
.monster::before,
.monster::after{
position: absolute;
top: -10px;
left: 50%;
content: '';
display: block;
width: 20%;
height: 10px;
border-radius: 10px;
background-color: #fff;
}
.monster::before{
transform: translateX(-70%) rotate(45deg);
}
.monster::after{
transform: translateX(-30%) rotate(-45deg);
}
.monster.blue{
background-color: #0c4475;
animation-delay: 0.5s;
}
.monster.blue .eyeball,
.monster.blue .mouth{
background-color: #db4d6d;
}
@keyframes jumping{
50%{
top: 0%;
box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
100%{
top: -50px;
box-shadow: 0 120px 20px rgba(0,0,0,0.1);
}
}
@keyframes run{
0%,10%{
transform: translateX(50%);
}
90%,100%{
transform: translateX(-50%);
}
}
.pageloading{
width: 100%;
height: 100%;
background-color: #0c4475;
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
transition: opacity 0.5s;
}
.pageloading .loading{
width:200px ;
height: 8px;
margin-top:50px;
background-color: #fff;
border-radius: 5px;
overflow: hidden;
}
.pageloading .loading .bar{
width: 0%;
height: 100%;
background-color: #db4d6d;
}
.pageloading.complete{
opacity: 0;
}
.pageloading.complete .monster{
transition: 0.5s;
transform:rotateZ(360deg) scale(0.1);
}
</style>
</head>
<body>
<div>
<h2 class="monsterText">Hello
<br>There
</h2>
<h3 class="opText">Ahhhh We'll eat you</h3>
</div>
<div class="monster">
<div class="eye">
<div class="eyeball"></div>
</div>
<div class="mouth"></div>
</div>
<div class="monster blue">
<div class="eye">
<div class="eyeball"></div>
</div>
<div class="mouth"></div>
</div>
<div class="pageloading">
<div class="monster">
<div class="eye">
<div class="eyeball"></div>
</div>
<div class="mouth"></div>
</div>
<div class="loading">
<div class="bar"></div>
</div>
</div>
<script src="jquery.js"></script>
<script>
var per = 0;
var timer;
timer = setInterval(function(){
$('.bar').css('width',per+'%');
per+=1;
if(per > 100){
$('.pageloading').addClass('complete');
setTimeout(function(){
$('.monsterText').html('<h2>哇哇哇哇哇哇</h2>');
},3000)
clearInterval(timer);
}
},30)
</script>
</body>
</html>
2.实现效果