Jump to content
Search Community

Cancel timeline on first scroll

ChunkyApps test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

My own solution was to get rid of the repeat in the timeline and do a check at the end of the animation. If scrollY is 0 I restart the timeline. It works but I'd still like a timeline repeatIf function.

 

Or better yet, use ScrollTrigger to cancel the timeline animation and hide the element so I don't have to wait until it plays to the end.

 

tlScrollArrow = gsap.timeline()
  .to('#scroll-1', {opacity: 1, duration: 0.3})
  .to('#scroll-1', {y: 20, duration: 2, ease: 'power1.out'}, 0.1)
  .to('#scroll-1', {opacity: 0, duration: 1.5}, 0.4)
  .add( function() {
    if (window.scrollY == 0) {
      tlScrollArrow.restart()
    }
  })

 

Edited by ChunkyApps
Clarify my original intention
Link to comment
Share on other sites

  • Solution

Hi ChunkyApps!

 

You could just use an event listener if this is going to be a one time deal.

window.addEventListener("scroll", stopAnimation);

function stopAnimation() {
  window.removeEventListener("scroll", stopAnimation);
  tlScrollArrow.kill();
}

 

  • Like 6
Link to comment
Share on other sites

6 hours ago, OSUblake said:

Hi ChunkyApps!

 

You could just use an event listener if this is going to be a one time deal.


window.addEventListener("scroll", stopAnimation);

function stopAnimation() {
  window.removeEventListener("scroll", stopAnimation);
  tlScrollArrow.kill();
}

 

Thank you. Always  the simplest answer that eludes me. Or the urge to use ScrollTrigger for everything lol!

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