css动画
2018-08-19 本文已影响0人
请叫我Bob
如需在 CSS3 中创建动画,您需要学习 @keyframes 规则。
@keyframes 规则用于创建动画。在 @keyframes 中规定某项 CSS 样式,就能创建由当前样式逐渐改为新样式的动画效果。
实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.mast{
width: 722px;
height: 344px;
background-color: red;
margin: 300px auto;
position: relative;
}
.box{
width: 64px;
height: 166px;
background-color: rgb(255,255,255);
float: left;
padding: 5px 10px;
float: left;
margin-left: 80px;
margin-top: 50px;
display: inline-block;
animation: moving 1s ease 0s infinite alternate;
}
.box1{
width: 64px;
height: 166px;
background-color: rgb(0,19,0);
float: left;
padding: 5px 10px;
float: left;
margin-left: 31px;
margin-top: 50px;
display: inline-block;
animation: moving 1s ease 0.1s infinite alternate;
}
.box2{
width: 64px;
height: 166px;
background-color: rgb(173,255,46);
float: left;
padding: 5px 10px;
float: left;
margin-left: 31px;
margin-top: 50px;
display: inline-block;
animation: moving 1s ease 0.2s infinite alternate;
}
.box3{
width: 64px;
height: 166px;
background-color: rgb(255,193,205);
float: left;
padding: 5px 10px;
float: left;
margin-left: 31px;
margin-top: 50px;
display: inline-block;
animation: moving 1s ease 0.3s infinite alternate;
}
.box4{
width: 64px;
height: 166px;
background-color: rgb(0,255,255);
float: left;
padding: 5px 10px;
float: left;
margin-left: 31px;
margin-top: 50px;
display: inline-block;
animation: moving 1s ease 0.4s infinite alternate;
}
@keyframes moving{
from{
transform: scaleY(1);
}
to{
transform: scaleY(0.5);
}
}
h1{
display: inline-block;
position: absolute;
top: 250px;
left:300px;
}
</style>
</head>
<body>
<div class="mast">
<div class="box"></div>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<h1>loading...</h1>
</div>
</body>
</html>
动画效果: