如何将 svg 元素移动到 html5 个视频上并同时控制视频播放?
How to move svg elements over html5 video and control video playback at the same time?
<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;
}
<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;
}