1
我使用SVG,音頻和一些JavaScript創建交互式信息圖。XHTML元素音頻不允許作爲SVG元素的子元素
我可以驗證使用W3C Validator通過直接輸入文檔,但是,我在嘗試通過URI或文件上傳驗證時,此錯誤:
XHTML元素的音頻不允許作爲SVG元素的子
我錯過了什麼?我明白<audio>
是不是標準的SVG(實際上使用data-*
屬性同上)。我不明白的是爲什麼SVG標籤中的名稱空間聲明不夠用。
這裏是一個最低限度的情況下:
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:html="http://www.w3.org/1999/xhtml"
viewBox="0 0 640 640">
<defs>
<audio id="consonant_pig_audio" xmlns="http://www.w3.org/1999/xhtml"><source type="audio/mpeg" src="https://bilingueanglais.com/tmp/ipa-infographic-preview-v1/audio/IPA-PIG.mp3"/></audio>
</defs>
<title>SVG with audio</title>
<rect class="trigger" width="640" height="640" data-target="consonant_pig" />
<script><![CDATA[
/** Shortcut to querySelector **/
function $(sel) { return document.querySelector(sel); }
function $all(sel) { return document.querySelectorAll(sel); }
/** Execute when the SVG is ready **/
(function() {
$all('.trigger').forEach(function(element) {
element.addEventListener('click', function() {
var audio = $('#' + this.getAttribute('data-target') + '_audio');
if (audio !== null) {
try { audio.currentTime=0; } catch(e) {} audio.play();
}
}, false);
});
})();
]]></script>
</svg>
驗證器是舊的,DATA-屬性和音頻是新的(正在進行中的SVG 2規範的一部分)。 –
@RobertLongson這會使我的SVG在SVG 1.1下有效嗎? –
在SVG 1.1中,非SVG名稱空間中的所有元素都應嚴格爲foreignObject的子元素。實際上,這對於我認爲的音頻標籤來說實際上是不必要的。 –