关于typescript:domvcr-纯客户端的录制-DOM-动画生成-GIF-MP4

51次阅读

共计 894 个字符,预计需要花费 3 分钟才能阅读完成。

📦 装置

npm i dom-vcr

🦄 应用

录制 2s 生成 4 帧 GIF

须要装置 gif.js

import {createVcr} from 'dom-vcr'
import GIF from 'gif.js'

const dom = document.querySelector('#app')
const vcr = createVcr(dom, {
  interval: 500,
  gif: new GIF({workerScript: './node_modules/gif.js/dist/gif.worker.js',}),
})

vcr.record(2000)
  .then(() => vcr.render())
  .then(blob => {window.open(URL.createObjectURL(blob))
  })

手动加帧生成 GIF

须要装置 gif.js

import {createVcr} from 'dom-vcr'
import GIF from 'gif.js'

const dom = document.querySelector('#app')
const vcr = createVcr(dom, {
  interval: 1000,
  gif: new GIF({workerScript: './node_modules/gif.js/dist/gif.worker.js',}),
})

async function generate() {
  dom.style.backgroundColor = 'red'
  await vcr.addFrame()
  dom.style.backgroundColor = 'yellow'
  await vcr.addFrame()
  dom.style.backgroundColor = 'green'
  await vcr.addFrame()

  const blob = await vcr.render()
  window.open(URL.createObjectURL(blob))
}

generate()

CDN

<script src="https://unpkg.com/dom-vcr"></script>

github https://github.com/qq15725/do…

正文完
 0