gpt4 book ai didi

javascript - 通过javascript渲染

转载 作者:行者123 更新时间:2023-12-02 19:26:05 25 4
gpt4 key购买 nike

我一直在尝试通过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.jpgsvg代码:

<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 上不起作用)

最佳答案

This向您展示如何访问 <object> 的内容元素标签。

关于javascript - 通过javascript渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12040074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com