CSS动画-animation
动画是使元素从一种样式逐渐变化为另一种样式的效果。
使用百分比来规定变化发生的时间,或用关键词 “from” 和 “to”,等同于 0% 和 100%。0% 是动画的开始,100% 是动画的完成。为了得到最佳的浏览器支持,应始终定义 0% 和 100% 选择器。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
/* 1. 创建动画 */
@keyframes myanimation1 {
from { background-color: green; }
to { background-color: red; }
}
/* 2. 使用 animation 绑定动画 */
div.div1 {
width: 400px;
height: 400px;
background-color: yellow;
animation: myanimation1 2S;
}
@keyframes mymove
{
from { left: 0px; }
to { left: 200px; }
/* 等价于 */
/* 0% { left: 0px; }
100% { left: 200px; } */
}
div.div2 {
width: 400px;
height: 400px;
position:relative;
background-color: green;
animation: mymove 2S infinite;
}
</style>
</head>
<body>
<div class="div1"></div>
<hr>
<div class="div2"></div>
</body>
</html>