ajax load svg,javascript - svgjs - load external svg file - Stack Overflow

本文介绍了SVG.js v2及以上版本中svg.import.js插件的弃用,推荐使用内置的draw.svg方法。同时,指导如何通过Ajax加载外部SVG文件并传递内容到SVG.js实例。特别提到从Inkscape加载时,应选择Plain SVG格式以确保安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The svg.import.js plugin is obsolete as of SVG.js v2 and up, as stated here:

This is now built-in with the draw.svg() method. Here is an example in the docs:

However, you will need to load the SVG data, not a url. You can however load an external file using ajax and pass the file's contents to the SVG.js instance. Something like:

var ajax = new XMLHttpRequest()

ajax.open('GET', 'your/file.svg', true)

ajax.send()

ajax.onload = function(e) {

draw.svg(ajax.responseText)

}

Note: if you are loading files from Inkscape, it's safer to use the Plain SVG format.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值