Fire SVG animations (SMIL) when the SVG is visible

When requirements read “when visible” your brain should go straight to IntersectionObserver. That’s exactly what Zach is doing here to kick off an animation when it scrolls into view.

Except this animation is an SVG SMIL animation: an <animate>


The post Fire SVG animations (SMIL) when the SVG is visible appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

When requirements read “when visible” your brain should go straight to IntersectionObserver. That’s exactly what Zach is doing here to kick off an animation when it scrolls into view.

Except this animation is an SVG SMIL animation: an <animate> situation. SMIL animations have some kinda cool things they can do, like begin when another animation ends, which is something CSS doesn’t help with that much. Turns out SMIL has a JavaScript API as well, so it’s possible to kick off the animation on demand that way, while also respecting prefers-reduced-motion.

Also check this out:

.querySelectorAll(`:scope [begin="indefinite"]`);

That :scope thing is new to me.

Direct Link to ArticlePermalink


The post Fire SVG animations (SMIL) when the SVG is visible appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-09-07T17:54:12+00:00) Fire SVG animations (SMIL) when the SVG is visible. Retrieved from https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/

MLA
" » Fire SVG animations (SMIL) when the SVG is visible." Chris Coyier | Sciencx - Tuesday September 7, 2021, https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/
HARVARD
Chris Coyier | Sciencx Tuesday September 7, 2021 » Fire SVG animations (SMIL) when the SVG is visible., viewed ,<https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/>
VANCOUVER
Chris Coyier | Sciencx - » Fire SVG animations (SMIL) when the SVG is visible. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/
CHICAGO
" » Fire SVG animations (SMIL) when the SVG is visible." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/
IEEE
" » Fire SVG animations (SMIL) when the SVG is visible." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/. [Accessed: ]
rf:citation
» Fire SVG animations (SMIL) when the SVG is visible | Chris Coyier | Sciencx | https://www.scien.cx/2021/09/07/fire-svg-animations-smil-when-the-svg-is-visible-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.