CSS3Loading动画

病毒肆虐,只能宅在家中,手机越刷越恐慌,不如写点代码吧,在春天来临之前,让我们一边守望,也一边前行。
动画效果如图1:
CSS3Loading动画

图2
CSS3Loading动画

<!DOCTYPE html>
<html lang="en">
<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>loading动画</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
background-color: #db4d6d;
display: flex;
/*水平居中*/
justify-content: center;
/*垂直居中*/
align-items: center;
}
.monster {
width: 110px;
height: 110px;
border-radius: 20px;
/* 圆角 */
background-color: #e55a54;
margin: 10px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
/* 嘴巴和眼睛垂直排列 */
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
/* 阴影 */
position: relative;
/* 定位怪兽角 */
animation: jumping 0.8s infinite alternate;
}
.monster .eye {
width: 40%;
height: 40%;
border-radius: 50%;
background-color: #fff;
margin: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.monster .eye .eyeBall {
width: 50%;
height: 50%;
border-radius: 50%;
background-color: #0c4475;
animation: eyemove 1.6s infinite alternate;
}
.monster .mouth {
width: 32%;
height: 12px;
border-radius: 12px;
background-color: #fff;
}
.monster::before,
.monster::after {
position: absolute;
content: '';
display: block;
width: 20%;
height: 10px;
border-radius: 10px;
background-color: #fff;
top: -10px;
left: 50%;
}
.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 .eye .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 eyemove {
0%,
10% {
transform: translate(50%);
}
100%,
90% {
transform: translate(-50%);
}
}
.pageLoading {
width: 100%;
height: 100%;
background-color: #0c4475;
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transition:opacity 0.5s;
}
.pageLoading .loading {
width: 200px;
height: 8px;
background-color: #fff;
border-radius: 5px;
margin-top: 50px;
overflow: hidden;
}
.pageLoading .loading .bar {
width: 100%;
height: 100%;
background-color: #db4d6d;
}
.pageLoading.complete
{
opacity: 0;
}
.pageLoading.complete .monster{
transition: 0.5s;
transform:scale(0.1) rotateZ(360deg);
}
.monsterText
{
color: #fff;
}
</style>
</head>
<body>
<h2 class="monsterText">Hello<br> world
</h2>
<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="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
var per=0;
var timer;
timer=setInterval(function()
{
$('.bar').css('width',per+'%');
per+=1;
if(per>100)
{
$('.pageLoading').addClass("complete");
setTimeout(() => {
$('.monsterText').html('<h2>We are Monster</h2>')
}, 3000);
clearInterval(timer);
}
},30)
</script>
</body>
</html>