Share Posted January 31, 2020 Hi, I wander how can I make the delay prop work every time I call .play() method. I also tried to chain the .delay(s) method like tween.delay(1).play() but it did't work. ☹️ Someone more experienced can help me pls? Thanks See the Pen mdyZxew?editors=0010 by giuliocollesei (@giuliocollesei) on CodePen Link to comment Share on other sites More sharing options...
Share Posted January 31, 2020 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 } 4 Link to comment Share on other sites More sharing options...
Share Posted January 31, 2020 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 } 3 Link to comment Share on other sites More sharing options...
Share Posted January 31, 2020 Another approach: use delayedCall. I also added a check to only allow users to click when the tween (including delay) is not active. See the Pen zYxVjRE?editors=0010 by GreenSock (@GreenSock) on CodePen 3 Link to comment Share on other sites More sharing options...
Author Share Posted January 31, 2020 All these suggestions are very helpful. Thank you guys! 😉👍 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now