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

📦 装置

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…

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理