css - 如何在多个字符串上使用 CSS 应用类型编写器动画

标签 css animation sass

我想在多个字符串上应用 type writer 动画,我看到大多数开发人员都是在 JS 中这样做的,但我只想用 CSS 来做,到目前为止我只为 2 个字符串做了但没有比那更多的。如果我为第三根弦做,第三根弦重叠。

Code pen link

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; }
}

关于css - 如何在多个字符串上使用 CSS 应用类型编写器动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59522834/

相关文章:

javascript - 为什么变换会移动整个坐标系而不是仅仅移动 SVG 中的元素?

html - 在标题 [CSS] 上显示图像的完整尺寸

html - 从 :before pseudo element 清除动画

css - Sass/Scss @mixin 也用于元素的选择器

css - 如何使 SCSS linter 接受蛇形小写和带连字符的小写作为选择器命名约定

css - 边距、边框、填充 - 具有不同结果的相同(大概)代码。请看一下

php - 使用 CSS 设置 PHP 样式

android - 在 Android 中停止 ObjectAnimators 的 AnimatorSet

javascript - 困难的网络动画

ruby - GulpJS : I don't want gulp-ruby-sass to loop through all sass files