Share Posted January 30, 2019 Hi Guys, I'm trying to create a timeline that has an infinite repeat, but the time between repeats is random every time (basically I've created a little timeline of some wind blowing through some plants, but I want the wind to appear random). I've done this with an eventCallback using onRepeat and a function that sets the repeatDelay every time. It's going mad though so I must be doing something wrong. I want it to play the animation through each time and then have a random amount of time between plays. My little codepen recreates the issue. Any ideas? Cheers Paul See the Pen LqbJgG by padders1980 (@padders1980) on CodePen Link to post Share on other sites
Share Posted January 30, 2019 Hi, In general is not recommended to fiddle with the values of a GSAP instance, is better to either create it again with the new values or, in your case, use other alternatives. The best approach I can think of is use a .call() method in the timeline when is completed to call a function that will restart the timeline after a random amount of time: var Box = new TimelineMax({ paused: true }); Box .to($('#square'), 1, {rotation:45}) .call(randomDelay) .play(); function randomDelay() { var newDelay = Math.random() * 3; TweenLite.delayedCall(newDelay, function() { Box.restart(); }); console.log("repeat after: ", newDelay); }; Also I see @mikel here, so He's probably working on a great solution as well, so don't just take my advice and wait for His as well. Happy Tweening!! 3 Link to post Share on other sites
Share Posted January 30, 2019 Hi @padders, How about this version ... See the Pen LqbXXq by mikeK (@mikeK) on CodePen Happy tweening ... Mikel 3 Link to post Share on other sites
Author Share Posted January 30, 2019 That's brilliant guys, I've used a combination of both of them and it works beautifully Thanks again. 3 Link to post Share on other sites
Share Posted January 30, 2019 Sounds like the guys already provided solid answers but here's one more simple approach: var Box = new TimelineLite({ onComplete:function() { TweenLite.delayedCall(Math.random() * 3, Box.restart, null, Box); } }); Box.to("#square", 1, {rotation:45}); 4 Link to post Share on other sites