fps
控制动画更新和渲染的全局帧率。
调整帧率可以帮助优化低端设备或同时运行多个复杂动画时的性能。但是,它可能会影响动画的感知流畅度。
engine.fps = 30; // Set all animations to update at 30 fps
接受
大于 0
的 数字
默认值
120
fps 代码示例
import { engine, animate, utils } from 'animejs';
const [ $container ] = utils.$('.container');
const [ $range ] = utils.$('.range');
for (let i = 0; i < 150; i++) {
const $particle = document.createElement('div');
$particle.classList.add('particle');
$container.appendChild($particle);
animate($particle, {
x: utils.random(-10, 10, 2) + 'rem',
y: utils.random(-3, 3, 2) + 'rem',
scale: [{ from: 0, to: 1 }, { to: 0 }],
delay: utils.random(0, 1000),
loop: true,
});
}
function onInput() {
engine.fps = this.value;
}
$range.addEventListener('input', onInput);
<div class="large row container"></div>
<div class="medium row">
<fieldset class="controls">
<input type="range" min=0 max=240 value=60 step=1 class="range" />
</fieldset>
</div>