Skip to content
Discussion options

You must be logged in to vote

Yes. Anime does not take arguments when you play an instance, but you don't need that. The callback is just a function, so you can have it read a variable that you change before each play.

this.mode = null;

this.transition = animate(this.x, {
  value: [0, 1, 0],
  autoplay: false,
  onUpdate: () => {
    if (this.x.value > 0.95) {
      if (this.mode === 'var1') { /* do this */ }
      if (this.mode === 'var2') { /* do this */ }
    }
  }
});

// later
this.mode = 'var2';
this.transition.restart();

If you'd rather keep one handler per behaviour, keep a map of handlers and look one up inside onUpdate:

const handlers = { var1: () => {}, var2: () => {}, var3: () => {} };
onUpdate: () => { if (

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@monolithMktg
Comment options

Answer selected by monolithMktg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants