onBeforeUpdate V4 JS
在运行动画的每一帧更新 tween 值之前,在指定的 frameRate
处执行函数。
接受
一个 Function
,其第一个参数返回动画本身
默认值
noop
要全局更改默认值,请更新 engine.defaults
对象。
import { engine } from 'animejs';
engine.defaults.onBeforeUpdate = self => console.log(self.id);
onBeforeUpdate 代码示例
import { animate, utils } from 'animejs';
const [ $value ] = utils.$('.value');
let mult = 1;
let updates = 0;
const animation = animate('.circle', {
x: '16rem',
loopDelay: 1500,
modifier: v => mult * v,
loop: true,
alternate: true,
onBeforeUpdate: self => {
$value.textContent = ++updates;
// Update the mult value just before updating the tweens
mult = 1 - self.iterationProgress;
}
});
<div class="large row">
<div class="circle"></div>
<pre class="large log row">
<span class="label">updates</span>
<span class="value">0</span>
</pre>
</div>