Jump to content
Search Community

Element within ScrollTrigger animation starts with no position offset

bewards test
Moderator Tag

Recommended Posts

From the codepen, the green component block near the bottom of the page has a list of cards. The parent component creates the overall timeline and each card element creates a tween with options and adds it to the timeline with the from method and an optional position (if position prop present within the gsap-tween-vars attribute).

 

The first two cards are working fine, but the last card breaks. After inspecting, it looks like the card does start off with the style value having the -120 translate, but once the progress starts, the card style attribute value becomes blank, so the card ends up jumping to it's normal position (seen in screenshot below). At some point in the scrolling progress, the 3rd card gets the style value back and does the animation like the rest of the cards. It looks like it gets the animation back once the position is met.


image.thumb.png.14946cda7bb8a83bf065cad5320082c3.png

 

 

If you reload the page in the middle of the animation, the page will reload and quickly scroll to after the start point, possibly avoiding the above style value removal and the 3rd card progress kicks in:

image.png.7e9d7c96163f84b483a40c876dc2b3e9.png

See the Pen rNzxOdz by bensewards (@bensewards) on CodePen

Link to comment
Share on other sites

Is there any chance you could provide just a minimal demo? The one you included has a ton of other stuff going on and leverages various other libraries. The key to troubleshooting this and getting a solid answer is isolating it as much as possible. 

 

Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. .

 

I think I see the issue you're talking about, but there are just so many other things going on and so many factors that it's very difficult to effectively get you an answer. 

Link to comment
Share on other sites

Hey Cassie -

 

Thanks for putting that together - it is what I am looking to achieve. When I first wrote this, I believe I was working with a version of GSAP (<3.9) that had me construct the scroll trigger differently. In my example, the scroll trigger manages the timeline in order to update the progress of the component timeline.

 

I'll take a closer look at the latest GSAP@3 to see if what I'm doing has to change.

  • Like 1
Link to comment
Share on other sites

Hey @Cassie - it's actually close to what I want to achieve, but the scrolling progress needs to control the timeline progress so that the animation scrubs forward instead of running all at once (in your above codepen, once the start trigger is hit, the animation runs fully)

Link to comment
Share on other sites

Scrub and toggleActions can't be used together. They have different use cases.

maybe?
 

once Boolean - If true, the ScrollTrigger will kill() itself as soon as the end position is reached once. This causes it to stop listening for scroll events and it becomes eligible for garbage collection. This will only call onEnter a maximum of one time as well. It does not kill the associated animation. It's perfect for times when you only want an animation to play once when scrolling forward and never get reset or replayed. It also sets the toggleActions to "play none none none".
  • Like 1
Link to comment
Share on other sites

Adding once worked. I didn't realize toggle actions couldn't also be used for scrubbing purposes.

 

I was looking to scrub in reverse ONLY WHEN onEnterBack. With the current implementation, the user can scrub in reverse all they want as long as they don't pass the end mark.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...