Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

How do I trigger the animation only once

So I have a slideshow built with Bootstrap Carousel, I have a couple items on the first 2 slides, SVGs that animate in. One is a logo drawn, the other fades in. The problem I am running into is the animation starts over when the slide cycles through once. I just want it to trigger on initial load, and then just have the SVGs static. I'm not sure how to do that. I assume JavaScript will be involved to check if the animations have been triggered, but I'm lost on if that's true or otherwise.

1 Answer

Steven Parker
Steven Parker
215,939 Points

I'm guessing these "animations" are actually CSS transitions? If so, one thing you could do is to include a special class in the CSS that will be present when the items are first loaded, but can be removed once they have been shown.

Removing the class can be done with a bit of JavaScript.