Jump to content
Search Community

Play an animation timeline before a ScrollTrigger

zhewar test
Moderator Tag

Recommended Posts

I want to run first timeline (tl) then when I scroll second timeline trigger (tl1) but when I run this code it gives me big gap on the top of my page, when I remove the Pin or change it to false it work perfectly fine, but when I set the pin to my section it create the gap.

so basically I want to create something like this apple page.

https://www.apple.com/airpods-3rd-generation/

    gsap.registerPlugin(ScrollTrigger, ScrollSmoother);

    var tl = gsap.timeline();
     
    tl.from("#img1", {scale:8,opacity: 1, duration: 1.5, ease: 'power1.easeOut'});
    tl.from("#img2", {scale:8, opacity: 1, duration: 1.5, ease: 'power1.easeOut'}, "-=1.5");
    tl.from("#title-txt", {fontSize: 30,opacity: 0, duration: 2, ease: 'power1.easeOut'},"-=0.5");

var tl1 = gsap.timeline({
    scrollTrigger: {
    trigger: '#img1',
    start: 'top top', 
    end: '+=1000',  
    scrub: 0.6,
    markers: true,
    anticipatePin: 1,
    pin: '.sec1'
        }
      });

      tl1.to("#img1", {x: "-100%", y: "-30%", duration: 1});
      tl1.to("#img2", {x: "100%", y: "30%", duration: 1}, "-=1");

See the Pen bGvjbqj by zhewar799 (@zhewar799) on CodePen

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. 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. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Hi @zhewar welcome to the forum!

 

You're trying to animate your trigger element, you never want to animate the element that is also your trigger, this will create some weird behavior because your trigger element is moving while scrolling.

 

Also there is a property called xPercent and yPercent, these are for animating based on percentage, so better to use those, instead of `x` and `y`.  And at your last tween you set the position parameter to '-=1' this is fine, but you could also set it to '<' then it will animate at the same time with the previous tween, no matter what time the previous tween takes.

 

To me this animation seems to run fine now, was this what you are looking for?

 

See the Pen MWVBgdw?editors=1010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 2
  • Thanks 1
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...