我用SVG創建了一個沙漏動畫。 它在鉻& &歌劇,但在Firefox上有一些問題工作正常。在Firefox中SVG路徑動畫訪問數據不工作
沙漏可以暫停,然後再恢復。現在在Chrome/Opera中,我可以讀取d
的當前值,然後將其應用於resume中的動畫元素,但是在firefox中,屬性未更新,因此我無法將當前屬性值分配給恢復的元素。
我試過了: 使用Element.animate()API,但它也不會改變元素的當前值。 使用getComputedStyle()方法,但它不能得到d
的值,因爲firefox沒有將其引用爲css屬性。
這是示例代碼: svg.html <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <path d="M 0 0 L 0 200 L 200 200 L 0 0 Z" fill="black" id="myPath"/> </svg>
svg.js
var myPath = document.getElementById('myPath');
var anima = document.createElementNS('http://www.w3.org/2000/svg', 'animate');
anima.setAttributeNS('', 'attributeType', 'XML');
anima.setAttributeNS('', 'attributeName', 'd');
anima.setAttributeNS('', 'values', 'M 0 0 L 0 200 L 200 200 L 0 0 Z; M 0 0 L 100 100 L 200 200 L 0 0 Z');
anima.setAttributeNS('', 'dur', '5s');
anima.setAttributeNS('', 'fill', 'freeze');
myPath.appendChild(anima);
myPath.lastChild.beginElement();
setTimeout(() => {
console.log(myPath.getAttribute('d')); // in chrome gives the current value, in firefox gives the element original value
}, 1500)
的問題是:1。 如何獲得在Firefox當前d
價值? 2.沒有額外的圖書館可能嗎?
我做了一個simple example
這是hourglass如果有人想看看它需要
任何人都知道的東西呢?
使用mypath.animatedPathSegList獲取當前值。 https://www.w3.org/TR/SVG11/paths.html#InterfaceSVGPathSegList –
@RobertLongson它給我的觀點,雖然它不像在鉻中那麼直截了當。但我想我可以將它處理成我需要的東西,thx! – cowCrazy