将 HTML 中文本内容的 JS 动画导出为动画 gif 或 PowerPoint 可导入 canvas 对象

Exporting JS Animation of Text Content in HTML to an animated gif or a PowerPoint importable canvas object

我的目标是将 JS 动画导入 PowerPoint 以用于幻灯片。我该如何实现?

我不是在寻找代我完成的工作。我需要一些有关完成此任务的技巧的建议。

幻灯片背景(透明背景动画后面)

这是HTML/JS动画。

// ——————————————————————————————————————————————————
        // TextScramble
        // ——————————————————————————————————————————————————

        class TextScramble {
            constructor(elm, numWords) {
                this.el = el
                this.numWords = numWords;
                this.chars = '!\<>-_\/[]{}—=+*^?#1234567890________'
                this.update = this.update.bind(this)
            }
            setText(newText) {
                const oldText = this.el.innerText
                const length = Math.max(oldText.length, newText.length)
                const promise = new Promise((resolve) => this.resolve = resolve)
                this.queue = []
                for (let i = 0; i < length; i++) {
                    const from = oldText[i] || ''
                    const to = newText[i] || ''
                    const start = Math.floor(Math.random() * 40)
                    const end = start + Math.floor(Math.random() * 40)
                    this.queue.push({ from, to, start, end })
                }
                cancelAnimationFrame(this.frameRequest)
                this.frame = 0
                this.update()
                return promise
            }
            update = () => {
                let output = ''
                let complete = 0
                for (let i = 0, n = this.queue.length; i < n; i++) {
                    let { from, to, start, end, char } = this.queue[i]
                    if (this.frame >= end) {
                        complete++
                        output += to
                    } else if (this.frame >= start) {
                        if (!char || Math.random() < 0.28) {
                            char = this.randomChar()
                            this.queue[i].char = char
                        }
                        output += `<span class="span">${char}</span>`
                    } else {
                        output += from
                    }
                }
                this.el.innerHTML = output
                if (complete === this.queue.length) {
                    this.resolve()
                } 
                else {
                    this.frameRequest = requestAnimationFrame(this.update)
                    this.frame++
                }
            }
            randomChar() {
                return this.chars[Math.floor(Math.random() * this.chars.length)]
            }
        }

        // ——————————————————————————————————————————————————
        // Example
        // ——————————————————————————————————————————————————

        const phrases = {
            'Programming' : 'none',
            'With' : 'none',
            'Ali': 'none',
            '<pwa/>': 'none',
            'Programming With Ali' : 'fade'
        }
        let phraseValues = Object.keys(phrases);
        const el = document.querySelector('.text')
        const fx = new TextScramble(el, phraseValues.length)

        let counter = 0
        let animation = phraseValues[0];

        let animate = (callback) => {
            debugger;
            callback();
            return function() {
                document.querySelector(".text").animate([
                   // keyframes
                   { opacity: '0' },
                   { opacity: '1' }
                ], {
                    // timing options
                    duration: 3500
                });
            }
        }   

        const next = () => {
        fx.setText(phraseValues[counter]).then(() => {
                if (counter < phraseValues.length-1)
                    setTimeout(next, 800)
                else {
                    setTimeout(() => {next, animate(next, fx.update)()}, 800)
                }
            })
            counter = (counter + 1) % phraseValues.length
        }
        next()
  html, body {
            font-family: 'Roboto Mono', monospace;
            background: #212121;
            height: 100%;
        }
        .container {
            height: 100%;
            width: 100%;
            justify-content: center;
            align-items: center;
            display: flex;
        }
        .text {
            font-weight: 100;
            font-size: 28px;
            color: #FAFAFA;
        }
        .dud {
            color: #757575;
        }
 <div class="container">
        <div class="text"></div>
    </div>

我最近遇到了类似的问题,我想为我的 Youtube 视频制作动画。我最终使用了 Puppeteer,逐步执行动画并使用 await page.screenshot({ path: screenshotFilename }); 将每一帧导出为单独的图像,然后将这些图像组合成动画。

我知道这不多,但希望这个回答对你有所帮助。