Jump to content
Search Community

There is a big margin after transform

Tati test
Moderator Tag

Recommended Posts

Hello. I can't solve the problem at all. Help me please. I have a .slogan element (bright circle on video) . I use yPercent: -50% for it. After that, I need to take another step in the animation, but after it there is a huge indent. If I remove transform, then the indent disappears. How can I solve this problem? 

 

 

const sloganTl = gsap.timeline({
            scrollTrigger: {
                trigger: '.double-section',
                start: 'top top',
                end: '+=850px',
                scrub: 2,
                pin: true,
                pinSpacing: false,
                // markers: true,
                onLeave: () => {
                    gsap.to('.nums', {
                        duration: 0.8,
                        scale: '0.2',
                        yPercent: -100
                    })
                    gsap.to('.slogan__bg', {
                        duration: 1,
                        clipPath: 'ellipse(51% 50% at 50% 50%)',
                        transformOrigin: 'center',
                        scale: 1.5
                    }, '<')
                    gsap.to('.slogan', {
                        duration: 1,
                        yPercent: -50
                    }, '<')
 
                },
                onEnterBack: () => {
                    gsap.to('.nums', {
                        duration: 1,
                        scale: '1',
                        yPercent: 0
                    })
                    gsap.to('.slogan__bg', {
                        duration: 1,
                        clipPath: 'ellipse(33% 50% at 50% 50%)',
                        transformOrigin: 'center',
                        scale: 1
                    }, '<')
                    gsap.to('.slogan', {
                        duration: 1,
                        yPercent: 0
                    }, '<')
                }
            }
        })
        sloganTl.fromTo('.slogan', {y: 500}, {
            duration: 0.5,
            y: 0,
        })
 
 
const sloganTl3 = gsap.timeline({
            scrollTrigger: {
                trigger: '.slogan',
                start: '80% center',
                end: '+=600px',
                markers: true,
                scrub: true
            }
        })
        sloganTl3.to('.slogan__bg', {
            duration: 0.5,
            clipPath: 'ellipse(33% 50% at 50% 50%)',
            transformOrigin: 'center',
            scale: 1,
        })
        sloganTl3.to('.slogan', {
            duration: 0.5,
            yPercent: -60
        }, '<')
        .from('.catalog', {
            duration: 0.5,
            scale: 0.6
        }, '<')
Link to comment
Share on other sites

Hi,

 

Without a minimal demo there is not much we can do.

 

The only things I can spot in your code are these:

const sloganTl = gsap.timeline({
  scrollTrigger: {
    trigger: '.double-section',
    start: 'top top',
    end: '+=850px',
    scrub: 2,
    pin: true,
    pinSpacing: false,
    // markers: true,
    onLeave: () => {
      gsap.to('.nums', {
        duration: 0.8,
        scale: '0.2',
        yPercent: -100
      })
      gsap.to('.slogan__bg', {
        duration: 1,
        clipPath: 'ellipse(51% 50% at 50% 50%)',
        transformOrigin: 'center',
        scale: 1.5
      }, '<')
      // THIS
      gsap.to('.slogan', {
        duration: 1,
        yPercent: -50
      }, '<')

    },
    onEnterBack: () => {
      gsap.to('.nums', {
        duration: 1,
        scale: '1',
        yPercent: 0
      })
      gsap.to('.slogan__bg', {
        duration: 1,
        clipPath: 'ellipse(33% 50% at 50% 50%)',
        transformOrigin: 'center',
        scale: 1
      }, '<')
      // THIS
      gsap.to('.slogan', {
        duration: 1,
        yPercent: 0
      }, '<')
    }
  }
})
// THIS HERE
sloganTl.fromTo('.slogan', {y: 500}, {
  duration: 0.5,
  y: 0,
})

You're using ScrollTrigger to scrub (2 seconds) the timeline's progress. Then in the fromTo() instance your target is ".slogan" but in your callbacks you have tweens that are affecting the same target. With that scrub time you can get to those callbacks and you will create new GSAP instances on the same target and the same properties.

 

Finally you are animating the yPercent value of the trigger element in your next timeline. That's definitely a no-no. Always avoid animating the trigger element of a ScrollTrigger instance, especially a property that could/will affect the vertical position of that trigger. Also you're animating the trigger's yPercent in your previous ScrollTrigger instance using scrub, that could also create problems.

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Thank you so mush. I changed the animation, but again have a problem. When I click any link to anchor, my site is very bad. All of animations are bad. What should I do to have actual position to scroll to them? 
 

gsap.set('.slogan', {
            y: 0
        })
        gsap.set('.catalog', {
            y: '-80vh',
            scale: 0.6
        })
        gsap.to('.slogan', {
            duration: 1,
            y: -200,
            ease: 'power1.in',
            scrollTrigger: {
                trigger: '.nums__inner',
                start: 'bottom 100%',
                end: 'top 20%',
                scrub: 1
            }
        })
        let sloganTl = gsap.timeline({
            scrollTrigger: {
                trigger: '.nums__inner',
                start: 'bottom center',
                end: '+=250px',
                ease: 'power1.easeInOut',
                toggleActions: 'play none none reverse'
            }
        })
        sloganTl.to('.nums', {
            scale: 0.5,
            yPercent: -100,
            duration: 0.8
        })
        .to('.slogan__bg', {
            duration: 0.8,
            clipPath: 'ellipse(36% 50% at 50% 50%)',
            transformOrigin: 'center',
            scale: 1.3
        },'<')
        .to('.slogan', {
            duration: 0.8,
            yPercent: -55,
        }, '<')
       
        // ScrollTrigger.refresh();
        let sloganTl3 = gsap.timeline({
            scrollTrigger: {
                trigger: '.catalog',
                start: 'top bottom',
                end: '+=250px',
                // scrub: 3,
                ease: 'power1.easeInOut',
                toggleActions: 'play none none reverse',
                markers: true
            }
        })
        sloganTl3.to('.catalog', {
            // duration: 1,
            scale: 1,
            duration: 0.8
        })
        .to('.slogan__bg', {
            duration: 0.8,
            clipPath: 'ellipse(27% 50% at 50% 50%)',
            transformOrigin: 'center',
            scale: 1
        },'<')
        .to('.slogan', {
            duration: 0.8,
            yPercent: -65,
        }, '<')
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

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