Jump to content
Search Community

Parallax effect to Hero

Trabajador test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi,

 

@Carl response in this thread should be a good starting point:

 

The main issue in your code though seems to be related to using the same trigger element for both sections in your loop

const mediaWrap = document.querySelectorAll('.page-hero');

mediaWrap.forEach(media => {
  const mediaImgs = media.querySelectorAll('.page-hero__bg img');
  mediaImgs.forEach(img => {
    const heightDiff = img.offsetHeight - img.parentElement.offsetHeight;
    const parallaxComp = 140;
    gsap.to(img.parentElement, {
      y: -heightDiff + parallaxComp,
      scale: 1.1,
      scrollTrigger: {
        trigger: mediaWrap,
        start: `top top`,
        scrub: 1.5,
      },
    });
  });
});

In your code mediaWrap is just one element and your page-hero sections are two, so both start at the same time.

 

I made a fork of your codepen here:

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

 

Hopefully this helps.

Happy Tweening!

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