前言
在很多网站首页介绍页里,为了吸引用户,暂留更长时间,使用了一些css3动画的
示例效果
实现这个动画原理
想要实现这个动画,改变元素的宽度,结合动画css3关键帧实现
具体代码如下所示
<!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>css3实现打字机效果</title>
<style>
.example-css3dayin {
text-align: center;
font-weight: 700;
font-size: 60px;
line-height: 79px;
background: linear-gradient( 270deg, rgba(198, 141, 255, 0.9) 8.92%, #5685ff 46.17%, #48d6ff 92.17% );
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-fill-color: transparent;
white-space: nowrap;
animation: animateText 4.7s steps(8) infinite;
-webkit-animation: animateText 4.7s steps(8) infinite;
}
@-webkit-keyframes animateText {
0% {
width: 0;
}
35% {
width: 8.1em;
}
75% {
width: 8.1em;
}
100% {
width: 0;
}
}
@keyframes animateText {
0% {
width: 0;
}
35% {
width: 8.1em;
}
75% {
width: 8.1em;
}
100% {
width: 0;
}
}
</style>
</head>
<body>
<p class="example-css3dayin">AI智能,引领未来</p>
</body>
</html></