用svg.js加载SVG文件 [英] Loading a SVG file with svg.js

查看:1494
本文介绍了用svg.js加载SVG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML5页面,里面有一个SVG元素。我想加载一个SVG文件,从中提取一些元素并用脚本逐个处理它们。

I have a HTML5 page with a SVG element in it. I would like to load a SVG file, extract some elements from it and dispose them one by one with a script.

我使用jQuery成功加载SVG文件,使用 .load(),在SV内插入了SVG树。但我想尝试 svg.js 来操作元素,但在文档中我找不到使用现有SVG初始化库的方法元素,我将获取对象。

I used jQuery to load the SVG file successfully, using .load(), having inserted the SVG tree inside the DOM. But I would like to try svg.js to manipulate the elements, but in the documentation I cannot find a way to initialize the library using an existing SVG element, where I will get the objects.

想法是访问加载的SVG元素(或直接用svg.js库加载),将单个对象复制到另一个元素,并在需要的地方移动它们。
怎么做?

Idea is to access the loaded SVG element (or load it directly with the svg.js library), copy the single objects to another element and move them where I need. How to do this?

推荐答案

你应该看一下 svg.import.js插件

文档说......

The documentation says...


所有导入的元素都会被存储。导入方法返回包含所有
存储元素的对象:

All imported elements with an id will be stored. The object with all stored elements is returned by the import method:



var rawSvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg [...]>"';
var draw = SVG('paper');
var store = draw.svg(rawSvg);

store.polygon1238.fill('#f06');

这篇关于用svg.js加载SVG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆