bendc / animateplus

A+ animation module for the modern web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delay animation

rizqinizamil opened this issue · comments

How can I delay animation after finish (inside the loop), before the animation start again?

Thanks,
Rizqi

Assuming I understood your question correctly, you could do something like this:

const params = new Map()
  .set("el", "div")
  .set("translateX", 200)
  .set("complete", () => animate(params.set("delay", 1000)));

animate(params);

Thanks @bendc, it works!

Hi @bendc, sorry I have another question.
How can I limit the loop? For example I only want to play animation 5 times.

Thanks.

const runAnimation = n => {
  let count = 0;

  const repeat = () => {
    if (count == 1) params.set("delay", 1000);
    if (count++ == n) return;
    animate(params);
  };

  const params = new Map()
    .set("el", "div")
    .set("translateX", 200)
    .set("complete", repeat);

  repeat();
};

runAnimation(5); // run animation 5 times

Sorry I'm bad at JS. Would you please take a look why it can't be repeat 5 times? https://jsfiddle.net/tvh7qc37/

You forgot .set("complete", repeat). You might also want to use var count instead of let count for wider compatibility.

Many thanks again. Sorry for bothering you.