在我的页面上,我有一个按钮和一个具有以下属性的画布 -
<button onclick="openSVG()">Open</button>
<canvas></canvas>
Run Code Online (Sandbox Code Playgroud)
单击按钮时,该openSVG()功能应该
fabric.loadSVGFromString()方法填充画布现在单击“打开”按钮会打开一个文件选择窗口,但不会将对象绘制到画布中。这是我的 openSVG() 函数 -
function openSVG() {
// importing file
var input = $(document.createElement('input'));
input.attr("id", "mySVGFile")
input.attr("type", "file");
input.trigger('click');
//storing file contents in var using FileReader
var myInputFile = document.getElementById('mySVGFile');
var myFile = myInputFile.files[0];
var fr = new FileReader();
fr.onload = function(){
var canvasD = this.result;
//loading data from var to canvas
fabric.loadSVGFromString(canvasD, function(objects, options) {
var obj = …Run Code Online (Sandbox Code Playgroud)