简单的动画
<!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>Document</title>
<style>
@keyframes run {
from {
transform: translateX(0px);
background-color: skyblue;
}
to {
transform:translateX(500px);
background-color: greenyellow;
}
}
.box {
width:100px;
height:100px;
background-color: pink;
animation: run 2s linear 0s infinite alternate;
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
</html>
注意:单位是:s 的一定要加上(animation: run 2s linear 0s infinite alternate;)
第一次没有写单位,找了好长时间的错误,就是没找到,最后还是通过请教别人,发现的。