then()

返回一个 Promise,该 Promise 在动画完成时解析并执行回调。

then() 方法可以直接内联如下:

animate(target, {x: 100, duration: 500}).then(callback);

或者在 async / await 上下文中使用:

async function waitForAnimationToComplete() {
  return animate(target, {
    x: 100,
    duration: 500,
  });
}

const asyncAnimation = await waitForAnimationToComplete();

参数

名称 类型
callback 一个 Function,其第一个参数是动画本身

返回

Promise

then() 代码示例

import { animate } from 'animejs';

const [ $value ] = utils.$('.value');

const animation = animate('.circle', {
  x: '16rem',
  delay: 500,
});

animation.then(() => $value.textContent = 'fulfilled');
<div class="large row">
  <div class="circle"></div>
  <pre class="large log row">
    <span class="label">promise status</span>
    <span class="value">pending</span>
  </pre>
</div>