autoplay

定义计时器的播放模式。

当计时器被添加到时间轴时,autoplay 参数不会生效,并且将被重写为 false

接受

布尔值 | onScroll()

  • If set to true the timer plays automatically
  • If set to false the timer has to be manually played
  • If set to onScroll() the timer will starts when the scroll thresholds conditions are met

默认

true

要全局更改默认值,请更新 engine.defaults 对象。

import { engine } from 'animejs';
engine.defaults.autoplay = false;

自动播放代码示例

const [ $time ] = utils.$('.time');
const [ $playButton ] = utils.$('.play');

const timer = createTimer({
  autoplay: false,
  onUpdate: self => $time.innerHTML = self.currentTime
});


const playTimer = () => timer.play();

$playButton.addEventListener('click', playTimer);
<div class="large centered row">
  <div class="half col">
    <pre class="large log row">
      <span class="label">current time</span>
      <span class="time value lcd">0</span>
    </pre>
  </div>
</div>
<div class="medium row">
  <fieldset class="controls">
    <button class="play">Play</button>
  </fieldset>
</div>