javascript - 如何将 svg 元素移动到 html5 视频上并同时控制视频播放?

标签 javascript css html5-video z-index svg-animate

<video id="video" width="600px" height="400px" autoplay playinline muted loop controls src="test.mp4"> 
</video>
<svg id="svg" width="600" height="400" style="position: absolute; left:8px; background:gray;opacity:0.5">
</svg>
<script>
    let svg_element = document.getElementById("svg");
    let svgns = "http://www.w3.org/2000/svg";
    setInterval(() => {

        let player_element = document.createElementNS(svgns, 'circle');
        player_element.setAttribute("id", "player");
        player_element.setAttribute("cx", 100);
        player_element.setAttribute("cy", 100);
        player_element.setAttribute("r", 40);
        player_element.setAttribute("stroke", "blue");
        player_element.setAttribute("stroke-width", 4);
        player_element.setAttribute("fill", "lightgreen");

        svg_element.appendChild(player_element);

        let animation = document.createElementNS(svgns, "animate")
        animation.setAttribute("attributeType", "XML")
        animation.setAttribute("attributeName", "cx")
        animation.setAttribute("dur", "2s")
        animation.setAttribute("to", 500)
        animation.setAttribute("from", 100)
        animation.setAttribute("fill", "freeze")
        animationID = "test"
        animation.setAttribute("id", animationID)
        player = document.getElementById("player")
        previous_animation = document.getElementById(animationID)
        if (previous_animation != null) {
            player.removeChild(previous_animation)
        }
        player.appendChild(animation)

        document.getElementById("svg").setCurrentTime(0);

    }, 1000);
</script>

这是源代码。 我在这里要做的是控制视频播放。 但是现在,我无法控制,因为 SVG 区域覆盖了它们。 我需要做什么? 圆形元素必须移动到视频上方。 将添加更多圈子。

最佳答案

你可以尝试像这样停止 svg 的指针事件

svg{
 pointer-events: none;
}

关于javascript - 如何将 svg 元素移动到 html5 视频上并同时控制视频播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58906072/

相关文章:

javascript - 注册表单(HTML、PHP 和 MySQL)在错误或缺失值后重定向

javascript - Firebase 服务错误 : Port 5000 is not open. 无法启动功能模拟器

javascript - 使用 JavaScript 从路径中获取文件名

javascript - VTT(字幕)不适用于外部网址

ruby-on-rails - 重新加载页面后静音视频工作有声

javascript - 引用错误 : invalid assignment left-hand side in console

css - Wordpress 谷歌字体后备

css - Bootstrap 行调整事件

html - 如何使用 Bootstrap 使页脚响应

html - 在 HTML5 Video 中,如何从一个长视频中播放一个小片段?