<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动画案例2</title>
<style>
div{
width: 200px;
height: 200px;
background-color: #f00;
}
/* 当网页加载完毕,div盒子自动从左边移动到右边 */
/* 1,定义动画-关键帧 */
@keyframes move {
0%{
/* left: 0; */
transform: translate(0,0);
width: 200px;
background-color: #f00;
}
100%{
/* left: 1000px; */
transform: translate(1000px,0); /* 要加px! */
width: 400px;
background-color: #0f0;
}
}
/* 2,调用动画 */
div {
/* position: absolute;
top: 0;
/* left: 0; 此时不要定位,但开始位置不会紧贴左上角 */
animation-name: move;
animation-duration: 3s;
}
</style>
</head>
<body>
<div></div>
</body>
</html>