安装
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
github https://github.com/qq15725/do...