【发布时间】:2015-09-02 00:49:03
【问题描述】:
截至目前,firefox 似乎不支持在
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
width="400"
height="400"
version="1.1">
<g
id="layer1">
<circle cx="200" cy="200" r="180" style="fill:#ccf"/>
<path
style="fill:none;stroke:#000000;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 200,200 200,30">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
from="0 200,200"
to="360 200,200"
dur="60s"
begin="1970-01-01T00:00:00Z"
repeatCount="indefinite"
/>
</path>
</g>
</svg>
如果我们将 begin= 更改为 0,它会进行动画处理,但不会与挂钟时间同步。为了与挂钟时间同步,我认为我们必须计算 begin 相对于文档开始时间的值。
当我通过 AJAX 获取数据时,随着时间的推移,我将向文档添加动画元素,因此计算 begin 属性的代码必须在文档生命周期中的任何时候工作。如果我们将这个脚本标签添加到动画中,它应该让问题的本质更清楚一点:
<script type="text/javascript">
function computeAnimationBegin()
{
// This is a toy function to illustrate the problem
var d1= new Date()
//console.log(d1.getTime())
d1.setSeconds(0)
d1.setMilliseconds(0)
return d1.getTime()
}
function wallclockToDocumentTime(t1)
{
// what magic goes here??
}
function adjustAnimation()
{
var elt = document.getElementById("a")
var t1 = computeAnimationBegin()
var val = wallclockToDocumentTime(t1)
console.log(val)
elt.setAttribute("begin", val)
}
window.onload = function() {
setInterval(adjustAnimation, 5*1000)
}
</script>
在 javascript 中,如何将挂钟时间映射到适合在 begin 属性中使用的值?
【问题讨论】:
-
我不知道有任何 UA 支持这个。
标签: javascript animation svg