Jump to content
Search Community

First animation keeps moving back on scrolling further

Avienda test
Moderator Tag

Recommended Posts

Im trying to make the intro text translate to the middle of the gallery photo, and keep it static during the clip-path animation applied on the image. Here is my code:

 


         const intro = document.querySelector(".intro-text");

        const introAnimation = gsap.to(myDiv, {y:500, duration: 2});

        ScrollTrigger.create({
            trigger: intro,
            start: () => 'center top+=' + document.querySelector('.gallery').offsetHeight / 3,
            end: "+=600",
            animation: introAnimation,
            scrub: 2,
        });

        const clipAnimation = gsap.fromTo(".hero-container", {
            clipPath: "inset(8% 29% 35% 29% round 0.75rem)"
        }, {
            clipPath: "inset(5% 5% 20% 5% round 0.75rem)",
            duration: 2
        });

        ScrollTrigger.create({
            animation: clipAnimation,
            trigger: "#hero",
            start: () => 'center top+=' + document.querySelector('.gallery').offsetHeight / 3,
            endTrigger: "#hero-2",
            end: () => 'center top+=' + document.querySelector('.gallery').offsetHeight / 2,
            scrub: 2,
            pin: '.gallery',
            pinType: "transform",
            markers: true,
        });

The problem I face is, the intro text keeps scrolling back up during clip-path animation. I have struggled to find a solution to no avail. 

 

Would appreciate if anyone could shed some light on the issue. 

 

Disclosure: I am completely new to GSAP.

Thanks!

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/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

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, 

 

Thanks for getting back to me so soon. So I have tried to create a minimal code pen.

 

To my surprise there are more issues in the codepen result as the hero text jumps to position rather than smoothly translating down on scroll. But, it's still scrolling back up when the clip animation on the image starts. (Also, the image is supposed to be pinned at the centre of the screen but oddly in the code pen its pined at the bottom; locally it's pinned at the centre, needless to say i got it working by trial and error so I have no idea why it's behaving differently in the code pen). Any help would be appreciated much. 

 

Thanks

Avi

 

See the Pen ZEjKNpE by avienda (@avienda) on CodePen

 

Link to comment
Share on other sites

Hi,

 

Honestly I'm confused about how you expect this to work and how it differs from what I'm seeing in the codepen example.

 

If you ask me I think this is a perfect scenario to completely remove ScrollTrigger from this and focus just on the HTML/CSS first, then add GSAP in order to make the animations and be sure they work the way you expect. Once the HTML/CSS looks the way you want and your GSAP animations are happening, then you add ScrollTrigger to the mix. I know it sounds counter-intuitive, but is the best workflow me and many people around here use.

 

Please be as clear and specific about how this should work in order to offer you the best possible support and remember to start with the simplest setup and add-up until you add ScrollTrigger at the end.

 

Happy Tweening!

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...