这是代码必须删除单击按钮上的网格线我正在使用带有fabric.js的画布这里是链接
$("#ungrid").click(function() {
var a= fabric.GetLine();
alert(a);
var width = canvas.width;
var height = canvas.height;
var j = 0;
var line = null;
var rect = [];
var size = 20;
console.log(width + ":" + height);
for (var i = 0; i < Math.ceil(width / 20); ++i) {
rect[0] = i * size;
rect[1] = 0;
rect[2] = i * size;
rect[3] = height;
line = null;
line = new fabric.Line(rect, {
stroke: '#999',
opacity: 0.5
});
这是功能画布删除线 canvas.remove(line); // canvas.clear(line); line.selectable = false;
canvas.remove(line);
line.sendToBack();
}
for (i = 0; i < Math.ceil(height / 20); ++i) {
rect[0] = 0;
rect[1] = i * size;
rect[2] = width;
rect[3] = i * size;
line = null;
line = new fabric.Line(rect, {
stroke: '#999',
opacity: 0.5
});
line.selectable = false;
canvas.remove(line);
line.sendToBack();
}
canvas.remove(line);
canvas.renderAll();
}) ;