Jump to content
Search Community

zoom style on body, calculating scrolltrigger start and end points wrong

fonveton test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi @fonveton

 

I don't see any of the code you describe in your pen. I've also never heard of "zoom style", I know there is scale: in CSS, but not zoom. 

 

That said if your markers are off that probably means your animating your trigger element eg what you use as the trigger: myElement, is also what you're animating with gsap.to(myElement, {...}), these two can't be the same element otherwise the markers will always be off!

 

Hope it helps and happy tweening! 

Link to comment
Share on other sites

  • Solution

 

 

Hi,

 

As the spec says I wouldn't use zoom in any production site if I was you. That being said the MDN page states:

Quote

However, unlike CSS Transforms, zoom affects the layout size of the element.

 

That means that the entire layout of the document is being affected which changes the height of the document once the animation is completed. In this demo you can see the lower spacer section being pushed down because of that:

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

 

So every ScrollTrigger instance created after that will be affected since those calculations will have an offset created by the zoom level and the height of the document being updated because of it. What you could do is use an onLeave callback in order to call ScrollTrigger.refresh() only after the first run:

let firstRun = true;

gsap.to(".box", {
  zoom: 1.5,
  scrollTrigger: {
    trigger: ".box",
    start: "top center",
    end: "bottom center",
    scrub: true,
    onLeave: () => {
      if(firstRun) {
        firstRun = false;
        ScrollTrigger.refresh();
      }
    },
    markers: true,
  },
});

 

Hopefully this helps.

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