gpt4 book ai didi

html - 如何在不改变文字大小的情况下为每个字母设置动画

转载 作者:太空宇宙 更新时间:2023-11-03 20:11:23 25 4
gpt4 key购买 nike

我试图让每一个字母在悬停时变大。我得到了那个动画,但我想摆脱整个句子来移动。我尝试使用绝对定位;它没有用。

这里是 jsfiddle .

HTML:

<div>
<h1>
<span id='let-1'>S</span><span id='let-2'>a</span><span id='let-3'>m</span><span id='let-4'>p</span><span id='let-5'>l</span><span id='let-6'>e</span>
<span id='let-7'>T</span><span id='let-8'>e</span><span id='let-9'>x</span><span id='let-10'>t</span>
</h1>
</div>

CSS:

        h1 {
text-align: center;
}
span {
font-size: 3em;
}
div:hover span {
animation: .3s letters forwards;
}
#let-2 {
animation-delay: .1s;
}
#let-3 {
animation-delay: .2s;
}
#let-4 {
animation-delay: .3s;
}
#let-5 {
animation-delay: .4s;
}
#let-6 {
animation-delay: .5s;
}
#let-7 {
animation-delay: .6s;
}
#let-8 {
animation-delay: .7s;
}
#let-9 {
animation-delay: .8s;
}
#let-10 {
animation-delay: .9s;
}
@-webkit-keyframes letters {
from,to {font-size: 3em;}
50% {font-size: 4em;}
}
@keyframes letters {
from,to {font-size: 3em;}
50% {font-size: 4em;}
}

最佳答案

您可以为 transform: scale() 设置动画,而不是为 font-size 属性设置动画

h1 {
text-align: center;

}
span {
font-size: 3em;
display: inline-block;
}
div:hover span {
animation: .3s letters forwards;
}
#let-2 {
animation-delay: .1s;
}
#let-3 {
animation-delay: .2s;
}
#let-4 {
animation-delay: .3s;
}
#let-5 {
animation-delay: .4s;
}
#let-6 {
animation-delay: .5s;
}
#let-7 {
animation-delay: .6s;
}
#let-8 {
animation-delay: .7s;
}
#let-9 {
animation-delay: .8s;
}
#let-10 {
animation-delay: .9s;
}
@-webkit-keyframes letters {
from,to {transform: scale(1);}
50% {transform: scale(1.3);}
}
@keyframes letters {
from,to {transform: scale(1);}
50% {transform: scale(1.3);}
}
<div>
<h1>
<span id='let-1'>S</span><span id='let-2'>a</span><span id='let-3'>m</span><span id='let-4'>p</span><span id='let-5'>l</span><span id='let-6'>e</span>
<span id='let-7'>T</span><span id='let-8'>e</span><span id='let-9'>x</span><span id='let-10'>t</span>
</h1>
</div>

关于html - 如何在不改变文字大小的情况下为每个字母设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024534/

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