Jump to content
Search Community

How to make delay prop work every yime

Sketchin test
Moderator Tag

Recommended Posts

Hi Sketchin,

 

you could use i.e. timeline for this. Would it be a solution for you ?  The last parameter inserts the tween at 1 which will be respected every time you restart the timeline.

 

var toggle = document.getElementById('toggle')
toggle.addEventListener('click', toggleHandler, false)

var tl = gsap.timeline({paused:true});
tl.fromTo('#square', 1, {
  x: 0,}, {
  x: 500
},1);
var state = true;

function toggleHandler() {
  if (state) {
    tl.play()
  } else {
    tl.reverse()
  }
  // Update state
  state = !state
}

 

  • Like 4
Link to comment
Share on other sites

Hey @themepunch that's a clever solution! Good to see you helping out.

 

Another approach is to use restart(true). The true means delays will be honored: https://greensock.com/docs/v3/GSAP/Tween/restart()

 

function toggleHandler() {
  if (state) {
    tween.restart(true)
  } else {
    tween.reverse()
  }
  // Update state
  state = !state
}

 

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