Jump to content
Search Community

Pausing then resuming a timeline

Jloafs test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi guys

 

I'm trying to figure out how to pause a timeline (between these .to) then add a button to resume the playback from the pause point. Any help would probably save me hours banging my head against a wall :-)

 

.to("element", {
      delay: -1,
      opacity: 1,
      y: "0",
      duration: 1.5,
      ease: Power4.easeOut,
    })
    .to("element", {
      delay: 5,
      opacity: 0,
      y: "-100vh",
      duration: 1.5,
      ease: Power4.easeOut,
    })

 

Link to comment
Share on other sites

  • Solution

Hi,

 

GSAP timeline instances have an addPause() method that should be exactly what you're looking for:

const tl = gsap.timeline()
  .to("element", {
    delay: -1,
    opacity: 1,
    y: "0",
    duration: 1.5,
    ease: Power4.easeOut,
  })
  .addPause()
  .to("element", {
    delay: 5,
    opacity: 0,
    y: "-100vh",
    duration: 1.5,
    ease: Power4.easeOut,
  });

const button = document.getElementById("button");
button.addEventListener("click", () => {
  tl.play();
});

https://greensock.com/docs/v3/GSAP/Timeline/addPause()

 

Let us know if you have other questions.

 

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