FabricJS - 选择对象时禁用图层索引更改

FabricJS - disable layer index changing when object is selected

我的 FabricJS 应用有问题。默认情况下,fabricjs中的对象层在我select它的时候跳到最上面

我想禁用这个选项,这样活动元素的索引就不会改变。有可能吗?

设置canvas.

时,您只需要设置preserveObjectStacking选项,如下代码所示

var fabricCanvas = new fabric.Canvas("t", { preserveObjectStacking: true });

fabricCanvas
  .add(new fabric.Rect({
    top: 0,
    left: 0,
    width: 100,
    height: 100,
    fill: "green"
  }))
  .add(new fabric.Rect({
    top: 50,
    left: 50,
    width: 100,
    height: 100,
    fill: "red"
  }))
  .add(new fabric.Rect({
    top: 100,
    left: 100,
    width: 100,
    height: 100,
    fill: "blue"
  }))
  .renderAll();
canvas {
  border: 1px solid black;
}
<canvas id="t" width="400" height="300"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.3/fabric.min.js"></script>