anime js - reset entire timeline (remove all previously added animations)

Viewed 1516

I can add animations to anime timeline using the timeline.add({parameters}) function. Is it possible to remove all the previously added animations and reset the whole timeline?

Thanks,

1 Answers

You can reset the timeline by calling the restart method:

const tl = anime.timeline({
  duration: 400,
  easing: 'easeInOutQuad',
})

tl.add({
  targets: '.box',
  rotate: 360,
  translateX: {
    value: 400,
    delay: 400,
  }
})

document.querySelector('button').addEventListener('click', () => {
    tl.restart();
});
Related