RxJS animationFrame

2020-09-25 17:54 更新

動(dòng)畫(huà)幀計(jì)劃程序

const animationFrame: any;

描述

執(zhí)行任務(wù)時(shí),window.requestAnimationFrame會(huì)開(kāi)除

當(dāng)animationFrame延遲使用調(diào)度程序時(shí),它將退回到async調(diào)度程序的行為。

無(wú)延遲,animationFrame調(diào)度可以用來(lái)創(chuàng)建流暢的瀏覽器的動(dòng)畫(huà)。它確保計(jì)劃的任務(wù)將在下一個(gè)瀏覽器內(nèi)容重新繪制之前發(fā)生,從而盡可能高效地執(zhí)行動(dòng)畫(huà)。

安排div高度動(dòng)畫(huà)

  1. // html: <div style="background: #0ff;"></div>
  2. import { animationFrameScheduler } from 'rxjs';
  3. const div = document.querySelector('div');
  4. animationFrameScheduler.schedule(function(height) {
  5. div.style.height = height + "px";
  6. this.schedule(height + 1); // `this` references currently executing Action,
  7. // which we reschedule with new state
  8. }, 0, 0);
  9. // You will see a div element growing in height
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)