简体   繁体   中英

How to disable multiselection on fabric.js canvas?

I'm currently working on a canvas built with fabric.js.

I have three objects on a canvas:

  1. First, that cannot be selected/resized/replaced
  2. Second,that behave the same as the first one
  3. And a third one, which can be replaced/selected etc.

My problem is that when I multiselect them (by using my mouse), they all became capable of resizing/replacing etc.

My question is: How can I disable grouping them together, so that the first two objects cannot be select?

I have already tried canvas.selection = false - but this option disables the whole canvas.

To disable the ability to click and drag in order to select multiple objects you can simply add a key:value pair in the options of the fabric.Canvas initialization...

let canvas = new fabric.Canvas("some_id_attribute_value",{selection: false});

The specific key value is selection:false and "some_id_attribute_value" is whatever you specified as the id of the canvas element(basic canvas init step). I was also having this problem, hope this helps!

I don't know if I follow your question but each object has a selectable property.
Perhaps that will help?

selectable : Boolean
When set to false , an object can not be selected for modification (using either point-click-based or group-based selection). But events still fire on it.

http://fabricjs.com/docs/fabric.Object.html#selectable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM