【发布时间】:2011-03-21 17:45:48
【问题描述】:
SVG 标准允许使用和引用外部 SVG 文件。
我有一个文件circle.svg,它定义了一个 ID 为“the_circle”的圆形对象。
从主 SVG 文件中,我可以使用 SVG linking 包含这个圆圈并为其设置动画。
我也想通过 javascript 访问同一个圆形对象,我该怎么做?
xlink:href="url(#the_image)#the_circle" 的 javascript 等价物是什么?
使用 document.getElementById('the_image') 我只能访问 SVGImageElement 而不能访问包含的 SVG 中定义的对象。
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<image
id="the_image"
x="0" y="0" width="100%" height="100%"
xlink:href="circle.svg" />
<animateTransform
xlink:href="url(#the_image)#the_circle"
attributeName="transform" attributeType="XML"
type="translate"
from="0" to="25"
dur="1s" repeatCount="indefinite"
additive="replace" fill="freeze" />
</svg>
【问题讨论】:
-
在 svg-developers tech.groups.yahoo.com/group/svg-developers/message/63940发布了同样的问题
标签: javascript dom svg