速度曲线步长
<!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>速度曲线步长</title>
<!-- 速度曲线-步长可以实现打字机效果 -->
<style>
div {
overflow: hidden;
font-size: 20px;
width: 0;
height: 30px;
background-color: brown;
/* 让我们的文字强制一行显示 */
word-spacing: nowrap;
/* steps 就是分几步完成动画,有了steps就不用写ease或者linear了 */
/* 分10步走完200像素 */
animation: w 4s steps(10) forwards;
}
@keyframes w {
0% {
width: 0;
}
100% {
width: 200px;
}
}
</style>
</head>
<body>
<div>世纪佳缘我在这里等你</div>
</body>
</html>
效果展示
02-奔跑的小熊案例
<!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>奔跑的小熊案例</title>
<style>
body {
background-color: #ccc;
}
div {
position: absolute;
width: 200px;
height: 100px;
background: url(../media/bear.png) no-repeat;
/* 元素可以添加多个动画,用逗号分隔 */
animation: bear 1s steps(8) infinite, move 3s forwards;
}
@keyframes bear {
0% {
background-position: 0 0;
}
100% {
background-position: -1600px 0;
}
}
@keyframes move {
0% {
left: 0;
}
/* 想要小熊在浏览器的中间,先让小熊走浏览器的一半,再减去div自己的一半 */
100% {
left: 50%;
/* 走自己宽度的一半 */
/* 1.margin-left: -100px; */
transform: translate(-50%);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
效果展示