<!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>动画案例3</title>
<style>
div{
width: 200px;
height: 200px;
margin: 10px;
background-color: #f00;
}
/* 当网页加载完毕,div盒子自动从左边移动到右边 */
/* 1,定义动画-关键帧 */
@keyframes move {
0%{
/* left: 0; */
transform: translate(0,0);
}
100%{
/* left: 1000px; */
transform: translate(1000px,0); /* 要加px! */
}
}
/* 2,调用动画 */
div {
/* position: absolute;
top: 0;
/* left: 0; 此时不要定位,但开始位置不会紧贴左上角 */
animation-name: move;
animation-duration: 3s;
animation-timing-function: linear;
/* animation-iteration-count: infinite; 无限次重复 */
/*animation-direction: alternate; 下一周期逆向播放 */
animation-fill-mode: forwards; /* 默认值为backwords */
}
div:last-of-type{ /* 后面加了一个结构伪类选择器,选择最后一个div */
animation-delay: 1s;
}
</style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>