如需在 CSS3 中創(chuàng)建動(dòng)畫蹬蚁,您需要學(xué)習(xí) @keyframes 規(guī)則沧竟。
@keyframes 規(guī)則用于創(chuàng)建動(dòng)畫。在 @keyframes 中規(guī)定某項(xiàng) CSS 樣式缚忧,就能創(chuàng)建由當(dāng)前樣式逐漸改為新樣式的動(dòng)畫效果悟泵。
實(shí)例:
<!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>
動(dòng)畫效果: