FabricJS-选择对象时禁用层索引更改 [英] FabricJS - disable layer index changing when object is selected

查看:90
本文介绍了FabricJS-选择对象时禁用层索引更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的FabricJS应用程序有问题.默认情况下,当我选择它时,fabricjs中的对象层会跳到顶部.

I've a problem with my FabricJS app. By default, the object layer in fabricjs jumps to the top when I select it.

我想禁用此选项,以使活动元素的索引不变.有可能吗?

I want to disable this option so that the index of the active element not changing. It's possible ?

推荐答案

设置画布时,只需设置以下代码中所示的preserveObjectStacking选项即可.

You just need to set the preserveObjectStacking options as shown in the below code when setting up the canvas.

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>

这篇关于FabricJS-选择对象时禁用层索引更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆