它与路径的坐标有关。让我们做一个简单的例子。
蓝色三角形是用绝对坐标定义的,如果没问题,则选择
它是用
canvas = new fabric.Canvas('myCanvas', { selection: false });
var path = new fabric.Path('M 0 0 L 0 100 L 100 100 Z');
path.set({ left: 20, top: 0, fill: 'blue', });
canvas.add(path);
canvas.renderAll();
如果我们像绿色三角形那样采用相对坐标,则选择不再正确地围绕对象。
canvas = new fabric.Canvas('myCanvas', { selection: false });
var path = new fabric.Path('M 20 20 l 0 100 l 100 0 Z');
path.set({ left: 20, top: 0, fill: 'green', });
canvas.add(path);
canvas.renderAll();
因此,如果我们为心脏采取另一条路径 (从维基百科复制而来)它会起作用。
canvas = new fabric.Canvas('myCanvas', { selection: false });
var path = new fabric.Path('M 272.70141,238.71731 \
C 206.46141,238.71731 152.70146,292.4773 152.70146,358.71731 \
C 152.70146,493.47282 288.63461,528.80461 381.26391,662.02535 \
C 468.83815,529.62199 609.82641,489.17075 609.82641,358.71731 \
C 609.82641,292.47731 556.06651,238.7173 489.82641,238.71731 \
C 441.77851,238.71731 400.42481,267.08774 381.26391,307.90481 \
C 362.10311,267.08773 320.74941,238.7173 272.70141,238.71731 \
z ');
var scale = 100 / path.width;
path.set({ left: 20, top: 0, scaleX: scale, scaleY: scale, fill: 'red', });
canvas.add(path);
canvas.renderAll();