How to move svg elements over html5 video and control video playback at the same time?

主宰稳场 提交于 2020-01-14 20:48:19

问题


<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>

This is a source code. What I want to do here is to control video play. But now, I can't control because the SVG area covers them. What do I have to do? The circle element must move above the video. More circles would be added.


回答1:


You could try stopping the pointer events of the svg like so

svg{
 pointer-events: none;
}


来源:https://stackoverflow.com/questions/58906072/how-to-move-svg-elements-over-html5-video-and-control-video-playback-at-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!