📹 Video
- Use the greensock TimelineMax's 🤔repeat property.
- A positive number will be the number of times an animation repeats, but a -1 will cause it to repeat indefinitely. Use -1 in this instance
const timeline = new TimelineMax({ repeat: -1 })
- If an animation is currently running, its 'isActive()' property will be true.
- If paused the 'isActive()' property will be false.
- Therefore a conditional is all that is needed to toggle an animation on and off.
document.getElementById("box").addEventListener('click', () => {
if(timeline.isActive()){
timeline.pause()
}else{
timeline.resume()
}
})
Check it out . . . You can now pause and resume your animation by clicking on the box.