Jump to content
Search Community

Pause timeline on rollover after tween complete

Woj test
Moderator Tag

Go to solution Solved by Carl,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hey guys,

 

I have a little timeline that cycles throw a series of slides automatically. On rollover the timeline is to pause. On rollout a timer is triggered and the timeline plays again. My issue is that I need the timeline to complete animating the slide in. Right now, rollover will just pause the animation in mid cycle.

See the Pen yOgpbZ by stevewojcik (@stevewojcik) on CodePen

Link to comment
Share on other sites

I tried using the isActive, but perhaps I dont really know the best way to utilize it. In this codepen if you rollover while its active the animation continues and you do get a console log notifying that the animation is indeed active. The problem is, I cant figure out how to then trigger the code to realize that the mouse is over the button and to not play any further animation.

 

See the Pen zqNRpw by stevewojcik (@stevewojcik) on CodePen

Link to comment
Share on other sites

  • Solution

Thanks for the demo. Very helpful.

 

I took a different approach

 

  1. use addPause() to pause the timeline after each slide comes in
  2. call a startTimer() function when paused
  3. startTimer() uses delayedCall() to wait 2 seconds before calling checkResume() function
  4. checkResume() tests if the mouse is over the button. if so the banner remains paused, if not the banner will resume.

 

the banner will only be paused when a full slide is present. the banner will resume as soon as the mouse leaves. 

 

var tl = new TimelineMax({paused: false});


tl.to(this.box, 1, { y:-250})
  .addPause("+=0", startTimer)
  .to(this.box, 1, {y:-500})
  .addPause("+=0", startTimer)
  .to(this.box, 1, {y:-750})
  .addPause("+=0", startTimer)
  .to(this.box, 1, {y:-1000})

this.button.addEventListener("mouseover", MouseOverHandler);
this.button.addEventListener("mouseout", MouseOutHandler);

var timer;

function startTimer(){
   console.log("timer restart")
   timer = TweenLite.delayedCall(2, checkResume);
}

function checkResume() {
  console.log("checkResume()");
  if(isOver){
    //if the mouse is over we do nothing for now
  } else {
    console.log("isOver == false so resume() timeline")
    tl.resume();
  }
}


//toggle value of isOver
function MouseOverHandler(e){
isOver = true;
}

function MouseOutHandler(e){
  isOver = false;
  console.log("mouseOutHandler called, let's resume()");
  tl.resume();
}

 

 

check out: http://codepen.io/GreenSock/pen/KzaoKa?editors=0010

 

 

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