Jump to content
Search Community

remove pin onLeaveBack

doughnut-hole test
Moderator Tag

Recommended Posts

ScrollTrigger.create({
  trigger: ".trigger-ele",
  pin: ".pin-ele",
  start: "top top",
  end: "bottom bottom"
});

I have a simple scroll trigger & pin function like above. Normally, it pins the element as well on scroll-up a page from bottom to top.

So I want to fire pin function only on enter a section, and do not on leave back, just want it to scroll back like a normal, "position: static" element.

 

How can I achieve this? Does anyone have an idea?

Link to comment
Share on other sites

const elementPin = ScrollTrigger.create({
  trigger: triggerEle,
  start: "top top",
  end: "bottom bottom",
  pin: pinEle,
  onLeave: () => {
    elementPin.disable(true)
  },
})

I just figured it out. just disable or kill it on leave. I'm not sure this is the best way though.

Link to comment
Share on other sites

Or you can try using the once property.

 

Quote

Boolean - If true, the ScrollTrigger will kill() itself as soon as the end position is reached once. This causes it to stop listening for scroll events and it becomes eligible for garbage collection. This will only call onEnter a maximum of one time as well. It does not kill the associated animation. It's perfect for times when you only want an animation to play once when scrolling forward and never get reset or replayed. It also sets the toggleActions to "play none none none".

 

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