then()
返回一个 Promise,当计时器完成时该 Promise 会被解析并执行回调。
then() 方法可以直接内联如下:
createTimer({duration: 500}).then(callback);
或者在 async / await 上下文中使用:
async function waitForTimerToComplete() {
return createTimer({ duration: 250 })
}
const asyncTimer = await waitForTimerToComplete();
参数
| 名称 | 类型 |
|---|---|
| callback | 一个 Function,其第一个参数是定时器自身 |
返回
Promise
then() 代码示例
import { createTimer, utils } from 'animejs';
const [ $status ] = utils.$('.status');
const [ $time ] = utils.$('.time');
createTimer({
duration: 2000,
onUpdate: self => $time.innerHTML = self.currentTime,
})
.then(() => $status.innerHTML = 'fulfilled');
<div class="large row">
<div class="col">
<pre class="large log row">
<span class="label">promise status</span>
<span class="status value">pending</span>
</pre>
</div>
<div class="col">
<pre class="large log row">
<span class="label">current time</span>
<span class="time value lcd">0</span>
</pre>
</div>
</div>