aki-sol Posted August 4, 2021 Share Posted August 4, 2021 Hello, I'm really excited to get the opportunity to work with gsap! I'm currently having an issue with reusing the same gsap function for multiple elements. My goal is, that each box-container gets triggered individually when they come into the viewport. Currently, the animation function is only applied to the first box-container, which is also the only one that has gotten a scrollTrigger marker applied to it. What I want however, is that each bock-container gets their own markers and is triggered individually. To me, my demo really makes sense but it's obviously not achieving what I need. I would really appreciate if someone could explain to me where I went wrong ^^ Thanks! Edit: I've changed the animations from when I first posted, but I added some comments to the codepen for later viewers that might experience the same problem to see the progression. See the Pen ExmeapK by aki-sol (@aki-sol) on CodePen Link to comment Share on other sites More sharing options...
Cassie Posted August 4, 2021 Share Posted August 4, 2021 This is one of the common ScrollTrigger mistakes. This article should help h 3 1 Link to comment Share on other sites More sharing options...
aki-sol Posted August 4, 2021 Author Share Posted August 4, 2021 Thanks a lot Cassie! It's a great article and it helped me find some mistakes! In the function that I initially set up I failed to use the identifier from the forEach() as the trigger. As advised by the article I also changed the gsap function from "from" to "fromTo" which helped with the proper timing of the animation starting for each module, even though I must admit I haven't really understood why this is the right solution yet. However, the animation is behaving strangely. I don't understand why the boxes jump back up and down at random times which in some cases also messes up the animation timing for the second container. I thought that setting an explicit end point would fix it but that does not see to be the problem here. Link to comment Share on other sites More sharing options...
Solution OSUblake Posted August 4, 2021 Solution Share Posted August 4, 2021 Perhaps you meant like this? See the Pen yLbxzZg by GreenSock (@GreenSock) on CodePen Elements can select their children. https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll 3 Link to comment Share on other sites More sharing options...
aki-sol Posted August 5, 2021 Author Share Posted August 5, 2021 Thanks @OSUblake ! It took me some time to find the tweak! I guess before I was targeting all boxes at once the the forEach function and going back to the article now I can see that I should have payed more attention to the comments in the example. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now