【发布时间】:2019-03-01 16:53:46
【问题描述】:
使用foreignObject,您可以在SVG 中使用<video> 标签,如下所示:
<foreignObject width="100" height="100" x="10" y="250">
<video xmlns="http://www.w3.org/1999/xhtml" style="background: #ffffff; width: 150px; height: 50px;">
<source src="https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"/>
</video>
</foreignObject>
但是,我似乎无法让视频元素遵守 chrome 中的 z-index 规则。
理论上,SVG 中的元素应该按照它们在组中的顺序呈现,这确实适用于普通的foreignObject 标签,例如,这可以正确呈现红色、白色和蓝色部分:
<rect x="10" y="10" width="200" height="200" fill="red"/>
<foreignObject width="100" height="100" x="10" y="50">
<div xmlns="http://www.w3.org/1999/xhtml" style="background: #ffffff; width: 150px; height: 50px;">
Hello World
</div>
</foreignObject>
<rect x="100" y="60" width="200" height="200" fill="blue"/>
...但是一旦您将<video> 粘贴在那里,它就不再起作用了。
这只是 chrome 中的一个错误吗?
我查看了错误跟踪器,虽然有大量与 SVG 相关的错误,但大多数相关错误都被标记为已解决。
我做错了吗?据我了解,SVG中<g>中项目的顺序应该决定z-index。
下面是一个最小的可重现测试用例。
(我也检查了 Firefox,但它也无法在那里工作......)
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="600px" viewBox="0 0 400 600" version="1.1">
<g>
<path style="fill-rule:nonzero;fill:rgb(72.54902%,100%,72.54902%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.636719 0.496094 L 593.5 0.496094 L 593.5 840.257812 L 0.636719 840.257812 Z M 0.636719 0.496094 "/>
<!-- Order is correctly rendered by sequence of elements in SVG -->
<rect x="10" y="10" width="200" height="200" fill="red"/>
<foreignObject width="100" height="100" x="10" y="50">
<div xmlns="http://www.w3.org/1999/xhtml" style="background: #ffffff; width: 150px; height: 50px;">
Hello World
</div>
</foreignObject>
<rect x="100" y="60" width="200" height="200" fill="blue"/>
<!-- Order is wrong for video element! -->
<rect x="10" y="300" width="200" height="200" fill="red"/>
<foreignObject width="100" height="100" x="10" y="250">
<video xmlns="http://www.w3.org/1999/xhtml" style="background: #ffffff; width: 150px; height: 50px;">
<source src="https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"/>
</video>
</foreignObject>
<rect x="100" y="360" width="200" height="200" fill="blue"/>
</g>
</svg>
【问题讨论】:
标签: svg html5-video