javascript - 如何使用 javascript/html 从 SVG 文件插入对象?

标签 javascript html svg

我有一个 SVG 文件,一层上有一堆不同的对象。是否可以在网页上显示文件中的特定对象而不先将对象拆分到它们自己的文件中?

最佳答案

这是 use 的完美用例元素...

https://developer.mozilla.org/en/docs/Web/SVG/Element/use :

The <use> element takes nodes from within the SVG document, and duplicates them somewhere else. The effect is the same as if the nodes were deeply cloned into a non-exposed DOM, and then pasted where the use element is


https://css-tricks.com/svg-use-with-external-reference-take-2/解释了如何将它用于 SVG 图标系统,其中所有图标都组合到一个 SVG 中。可能适合您的使用,或者至少更深入地了解其工作原理。

关于javascript - 如何使用 javascript/html 从 SVG 文件插入对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45691674/

相关文章:

javascript - Highcharts,导出时如何本地化语言

javascript - 渲染分页符中的多个谷歌图表

java - 使用 Apache Batik 从 SVG 生成 JPG

javascript - Owlcarousel2 - 如何检查最后一项

javascript - Rails 服务器告诉我---找不到类型为 'jquery-ui/datepicker' 的文件 'application/javascript'

javascript - 我如何浏览 json?

javascript - export * as bar VS export { 默认为 bar }

html - 如何使用 CSS 专注于 HTML 输入?

javascript - 我如何在 <a> 旁边的范围内显示所有 <a> 链接的 href

html - react 计算可滑动 View 的 View 宽度和高度