我正在尝试设计一个示例网页,并且我面临着svg的一些问题......
我创建了一个svg圆圈,上面有一条线,它将在圆圈中旋转。这是示例代码。
<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="100%" height="100%">
<circle cx="200" cy="200" r="100" stroke="black" stroke-width="4" fill="black" />
<g transform="translate(200,200)">
<line x1="0" y1="0" x2="100" y2="0" style="stroke:rgb(255,255,255);stroke-width:2">
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="25" to="360" dur="100s"/>
</line>
</svg>
在&#39;行&#39;上面的示例代码中当页面启动时会立即开始旋转,但是我想在按下START按钮后旋转线条,就像这样......
<input type="button" value=" START " onclick="start()" class="control-menu-top-btn" id="green-btn">
<script language="javascript" type="text/javascript">
function start()
{
.. ?
}
</script>
答案 0 :(得分:3)
beginElement方法将启动动画。在标记中将begin属性设置为indefinite将使其在javascript启动之前停止运行。
html, body {
width: 100%;
height: 100%;
}
&#13;
<input type="button" value=" START " onclick="start()" class="control-menu-top-btn" id="green-btn">
<script>
function start()
{
document.getElementById("transform").beginElement();
}
</script>
<svg width="100%" height="100%">
<circle cx="200" cy="200" r="100" stroke="black" stroke-width="4" fill="black" />
<g transform="translate(200,200)">
<line x1="0" y1="0" x2="100" y2="0" style="stroke:rgb(255,255,255);stroke-width:2">
<animateTransform id="transform" attributeName="transform"
attributeType="XML"
type="rotate"
from="25" to="360" dur="100s" begin="indefinite" />
</line>
</g>
</svg>
&#13;