gpt4 book ai didi

html - 如何以不同的延迟定位相同的动画

转载 作者:行者123 更新时间:2023-11-28 04:55:45 24 4
gpt4 key购买 nike

我有两个 div,每个包含一个词。每个单词中的每个字母都在一个 span 标签内,如下所示:

<div class="fade-in">
<span>h</span><span>e</span><span>l</span><span>l</span><span>o</span>
</div>

<div class="fade-in">
<span>w</span><span>o</span><span>r</span><span>l</span><span>d</span>
</div>

在我的 css 文件中,我创建了一个淡入淡出的动画,如下所示:

.fade-in span{
opacity: 0;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 2s;
animation-fill-mode: forwards;
}

@keyframes fadeInOpacity {
0% {opacity: 0;}
100% {opacity: 1;}
}

然后添加延迟以使字母按顺序淡出,如下所示:

.fade-in span:nth-child(1)  { animation-delay: 400ms; }
.fade-in span:nth-child(2) { animation-delay: 500ms; }
.fade-in span:nth-child(3) { animation-delay: 600ms; }
.fade-in span:nth-child(4) { animation-delay: 700ms; }
.fade-in span:nth-child(5) { animation-delay: 800ms; }

好吧,这行得通,但是两个词同时开始淡入。我想要的是第二个单词的第一个字母在第一个单词的最后一个字母之后开始淡入。我对开发还很陌生,但我猜肯定有比创建新动画更好的方法。

有没有办法为同一动画添加不同的延迟并针对不同的类或 ID?感谢您的宝贵时间。

最佳答案

HTML:

    <div class="fade-in" id="hello">
<span>h</span><span>e</span><span>l</span><span>l</span><span>o</span>
</div>

<div class="fade-in" id="world">
<span>w</span><span>o</span><span>r</span><span>l</span><span>d</span>
</div>

CSS:

    #hello .fade-in span:nth-child(1)  { animation-delay: 300ms; }
#hello .fade-in span:nth-child(2) { animation-delay: 400ms; }
#hello .fade-in span:nth-child(3) { animation-delay: 500ms; }
#hello .fade-in span:nth-child(4) { animation-delay: 600ms; }
#hello .fade-in span:nth-child(5) { animation-delay: 700ms; }


#world .fade-in span:nth-child(1) { animation-delay: 900ms; }
#world .fade-in span:nth-child(2) { animation-delay: 1000ms; }
#world .fade-in span:nth-child(3) { animation-delay: 1100ms; }
#world .fade-in span:nth-child(4) { animation-delay: 1200ms; }
#world .fade-in span:nth-child(5) { animation-delay: 1300ms; }

关于html - 如何以不同的延迟定位相同的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40409398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com