gpt4 book ai didi

svg - 未显示 defs/use 中的 foreignObject 中的 Canvas

转载 作者:行者123 更新时间:2023-12-01 06:36:57 25 4
gpt4 key购买 nike

我想使用 JavaScript 在嵌入在 svg(在 html5 页面中)的 html5 Canvas 上进行绘制。如果以这种方式绘制“cvs”就可以正常工作:

<svg id="fig" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1024px" height="1024px" viewBox="0 0 1024 1024">
<foreignObject x="0" y="0" width="512" height="512">
<body xmlns="http://www.w3.org/1999/xhtml">
<canvas id="cvs" width="512" height="512"></canvas>
</body>
</foreignObject>
</svg>

但如果在 Canvas 中完成并在 中引用,则不会使用 标签。图纸根本就没有出现。在 Safari 中检查元素告诉我 的尺寸使用 元素是 NaN x NaN; Firebug 说 0x0。
<svg id="fig" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1024px" height="1024px" viewBox="0 0 1024 1024">
<defs>
<foreignObject id="circles" x="0" y="0" width="512" height="512">
<body xmlns="http://www.w3.org/1999/xhtml">
<canvas id="cvs" width="512" height="512"></canvas>
</body>
</foreignObject>
</defs>
<use x="0" y="0" xlink:href="#circles"></use>
</svg>

这是一个错误吗?预期行为?我只是不明白如何使用foreignObject(很有可能)?

最佳答案

你不能直接指向一个 foreignObject 元素,它在 SVG specification 中是这样说的

“svg”、“symbol”、“g”、图形元素或其他仅“使用”。所以你可以指向一个 <g><svg>具有 <foreignObject> 的元素例如作为 child 的元素。

关于svg - 未显示 defs/use 中的 foreignObject 中的 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13937144/

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