css - 如何在多个字符串上使用 CSS 应用类型编写器动画
问题描述
我想type writer
在多个字符串上应用动画,我看到大多数开发人员都是在 JS 中做到这一点的,但我只想用 CSS 来做到这一点,到目前为止我只做了 2 个字符串,但仅此而已。如果我为 3rd string 做,3rd string 重叠。
HTML 代码。
<h1>I am Kirill
<div id="stmt1">Acquistion strategist</div>
<div id="stmt2">Campaign executioner</div>
<div id="stmt3">Semi-technical marketing lead</div>
</h1>
CSS 代码
#stmt2
{
margin-top:-40px;
}
#stmt1
{
width: 25em;
white-space: nowrap;
overflow: hidden;
animation: frag1type 10s steps(50, end) 0s infinite;
}
@keyframes frag1type{
from { width: 0; opacity:1; }
37%{width:25em;opacity:1; }
49%{width:0;opacity:1; }
100%{width:0;opacity:1; }
}
#stmt2
{
opacity: 0;
width: 25em;
white-space: nowrap;
overflow: hidden;
animation: frag2type 10s steps(50, end) 5s infinite;
}
@keyframes frag2type{
from { width: 0; opacity:1; }
37%{width:25em;opacity:1; }
49%{width:0;opacity:1; }
100%{width:0;opacity:1; }
}
#stmt3
{
margin-top: -40px;
}
#stmt3
{
opacity: 0;
width: 25em;
white-space: nowrap;
overflow: hidden;
animation: frag3type 10s steps(50, end) 7s infinite;
}
@keyframes frag3type{
from { width:0; opacity:1; }
37%{width:25em; opacity:1; }
49%{width:0; opacity:1; }
100%{width:0; opacity:1; }
}
解决方案
增加动画的时间15s
并增加动画的宽度10%
并减少动画25%
animation: frag1type 15s steps(50, end) 0s infinite;
animation: frag2type 15s steps(50, end) 5s infinite;
animation: frag3type 15s steps(50, end) 10s infinite;
@keyframes frag1type{
from { width: 0; opacity:1; }
10%{width:25em;opacity:1; }
25%{width:0;opacity:1; }
100%{width:0;opacity:1; }
}
@keyframes frag2type{
from { width: 0; opacity:1; }
10%{width:25em;opacity:1; }
25%{width:0;opacity:1; }
100%{width:0;opacity:1; }
}
@keyframes frag3type{
from { width: 0; opacity:1; }
10%{width:25em;opacity:1; }
25%{width:0;opacity:1; }
100%{width:0;opacity:1; }
}
推荐阅读
- java - 使用spring验证:在包含@valid和验证注释的restful服务中没有返回消息
- wordpress - 添加卷后 Docker 速度很慢(Wordpress)
- erlang - 为什么 kerl 不支持 HiPe for Linux?
- macos-catalina - Mac Catalina 上的 Mamp-PRO 6.x 无法再通过我的网站访问文件夹
- javascript - JQuery 自动提交在 Safari 中不起作用
- sympy - 获取 sympy 表达式中单项式的系数
- c# - SQL - ASP.NET Core 2.1.7 中的有意注入
- javascript - 我怎样才能改变输入范围的蓝色?
- html - 表格行的css插入框阴影?
- wpf - 如何在 WPF 中为 DataGridColumnHeader 创建工具提示?