新增第131个小实例:纯CSS实现打字动画特效
This commit is contained in:
parent
5fda20e758
commit
1f2fd685a6
|
@ -137,4 +137,5 @@
|
|||
127. HTML5+CSS3小实例:带标题的图像悬停效果
|
||||
128. HTML5+CSS3小实例:纯CSS实现简约的天气图标动画特效
|
||||
129. HTML5+CSS3小实例:纯CSS实现简约的天气图标动画特效(下)
|
||||
130. HTML5+CSS3小实例:传送带式的loading加载动画
|
||||
130. HTML5+CSS3小实例:传送带式的loading加载动画
|
||||
131. HTML5+CSS3小实例:纯CSS实现打字动画特效
|
|
@ -0,0 +1,67 @@
|
|||
*{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body{
|
||||
/* 100%窗口高度 */
|
||||
height: 100vh;
|
||||
/* 弹性布局 水平+垂直居中 */
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #222;
|
||||
}
|
||||
.text{
|
||||
/* 相对定位 */
|
||||
position: relative;
|
||||
color: #fff;
|
||||
font-size: 62px;
|
||||
/* 字间距 */
|
||||
letter-spacing: 3px;
|
||||
/* 单个字宽度 */
|
||||
width: 65px;
|
||||
/* 不换行 */
|
||||
white-space: nowrap;
|
||||
/* 溢出隐藏 */
|
||||
overflow: hidden;
|
||||
/* 自定义属性(变量),通过var函数进行调用,这里用来记录字数(6个字,根据你的实际字数而定) */
|
||||
--count: 6;
|
||||
/* 执行动画: 动画名 时长 分步过渡(这里分6步) 停留在最后一帧 */
|
||||
/* 时长要根据字数而定,字数多的话要适当延长 */
|
||||
animation: typing 1.8s steps(var(--count)) forwards;
|
||||
/* 加个倒影可能会比较好看 */
|
||||
-webkit-box-reflect: below 1px linear-gradient(transparent 30%,rgba(0,0,0,0.05));
|
||||
}
|
||||
/* 光标 */
|
||||
.text::after{
|
||||
content: "";
|
||||
width: 2px;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
background-color: #fff;
|
||||
/* 执行光标动画: 动画名 时长 线性的 无限次播放 */
|
||||
animation: blink 1s linear infinite;
|
||||
}
|
||||
|
||||
/* 定义动画 */
|
||||
/* 光标闪烁 */
|
||||
@keyframes blink {
|
||||
0%,49%{
|
||||
opacity: 0;
|
||||
}
|
||||
50%,100%{
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
/* 打字动画 */
|
||||
@keyframes typing {
|
||||
0%{
|
||||
width: 0;
|
||||
}
|
||||
100%{
|
||||
/* 计算字全部显示完的宽度,65px表示单个字宽度 */
|
||||
width: calc(var(--count) * 65px);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
|
||||
|
||||
<title>纯CSS实现打字动画特效</title>
|
||||
<link rel="stylesheet" href="131.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="text">
|
||||
打字动画特效
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue