Generates an video or GIF from a DOM node using HTML5 canvas and SVG
English | 简体中文
npm i dom-vcr
# optional deps
npm i modern-gif # by export GIF
npm i modern-mp4 # by export MP4
npm i mp4box
CDN
<script src="https://unpkg.com/dom-vcr"></script>
import { createVcr } from 'dom-vcr'
const dom = document.querySelector('#app')
const vcr = createVcr(dom, {
type: 'webm',
interval: 1000,
})
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()
MP4
Need install
mp4box
、modern-mp4
import { createVcr } from 'dom-vcr'
const dom = document.querySelector('#app')
const vcr = createVcr(dom, {
type: 'mp4',
interval: 1000,
})
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()
GIF
Need install
modern-gif
import { createVcr } from 'dom-vcr'
const dom = document.querySelector('#app')
const vcr = createVcr(dom, {
type: 'gif',
interval: 1000,
})
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()