【发布时间】:2012-08-15 22:13:05
【问题描述】:
我一直在尝试通过 javascript 呈现 svg 图像。尝试了各种选择,但最终不得不解决这个问题。
我已经像这样在 html 中声明了一个对象 id
<object id="gauge1" type="image/svg+xml" data="gauge.svg" width="127" height="122"/>
现在,我一直在尝试通过 javascript 访问这个 gauge.svg。我已经创建了一个像这样的嵌入类型的元素
this.m_svg = document.createElement('embed');
a 然后尝试使用setAttribute 访问图像,但没有成功。有什么建议?
同时将 svg 代码与图像一起粘贴到此处。
图片:https://sphotos-b.xx.fbcdn.net/hphotos-snc6/179594_10150982737360698_1827200234_n.jpg svg代码:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g name="gauge" width="122px" height="127px">
<image xlink:href="gauging.png" width="122" height="127"/>
<circle id="led" cx="39" cy="76" r="5" style="fill: #999; stroke: none">
<animateColor id="ledAnimation" attributeName="fill" attributeType="css" begin="0s" dur="1s"
values="none;#f88;#f00;#f88;none;" repeatCount="0"/>
</circle>
<g id="needle" transform="rotate(0,62,62)">
<circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/>
<rect transform="rotate(-130,62,62)" name="arrow" x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/>
<polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/>
</g>
<text id="value" x="51" y="98" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text>
</g>
</svg>
PS : 已经尝试过 this.m_svg.innerHTML = svg 代码(不适用于 safari)
【问题讨论】:
-
这不是那个问题的重复。在那个问题中,图像被加载,如何访问图像的内容是问题。
-
第一个链接再次提到第二个链接。所以那也不是重复的。
-
不知道你在那之后是什么,其他问题的答案确实包括在脚本中从
标签: javascript image web svg render