How to animate text like this?
Hi guys. I am struggling to replicate this animation : https://www.veed.io/view/31810767-8caa-4f6b-8212-273bdd17dfbd?panel=share. i want a word to fade out just as in next word fades in. Any help i would be greatly thankful.
Srajan
VEED
VEED - Screen Recording - Oct 9, 2023
Make stunning videos with a single click. Cut, trim, crop, add subtitles and more. Online, no account needed. Try it now, free. VEED
6 Replies
One quick way to do it:
https://codepen.io/Christian-Lorenz/pen/yLGGZRy
the 1000 in the setInterval is the text change in ms,
the 750ms in css the transition time to fade in / out.
I worked up a couple ways to accomplish the effect. One uses keyframes like:
The other uses the
<animate>
tag in a SVG:
I'd probably go with the SVG method. It's easier to insert into the flow & it's more flexible when editing because elements start relative to each other rather than on an absolute timeline.Ui, this is a very creative approach without using javascript. Props for that! But I think JS is the way to go here when it comes to reusability or dynamic text changes. But really a nice approach.
Btw. Does it really need svgs? All in all you're just setting animation delays for each text element which you could also do with animation-delay in css?
It depends on the situation. I can more easily get more complex behaviors out of the SVG animated using SMIL, say I want the durations to vary or I want to sync the animation of multiple properties simultaneously.
Note that the
begin
property of the second element is anim1.end
. That type of event-based triggering is only available in SMIL which only works on SVGs.
I did an example only using animation-delay
, but it's not possible to loop it.Ah ok. Well I'm just looping through the childnodes adding / removing a opacity class - no matter how many childnodes (texts) are in there.
I've also found learning SVG animations useful for doing NFTs because they frequently display in contexts where JavaScript is disabled (i.e. from within an
<img>
tag).