javascript 在 Fabric.js 中禁用组选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21630288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:21:27  来源:igfitidea点击:

Disable group selection in Fabric.js

javascriptfabricjs

提问by Timo K?hk?nen

How to disable group selection in Fabric.js and leave single objects selectable one at a time? With group selection I mean selecting multiple objects using eg. SHIFT+Click.

如何在 Fabric.js 中禁用组选择并一次选择一个对象?对于组选择,我的意思是使用例如选择多个对象。Shift + 单击。

回答by Dakshika

you can easily achieve this with

你可以很容易地做到这一点

  canvas.selection = false; // disable group selection

if you want it on individual object

如果你想在单个对象上使用它

  rect.set('selectable', false); // make object unselectable

回答by CQ Smooth

Disable group selection via selection listener canvas method (in my opinion the best way)

通过选择侦听器画布方法禁用组选择(在我看来是最好的方法)

canvas.on('selection:created', (e) => {
  if(e.target.type === 'activeSelection') {
    canvas.discardActiveObject();
  } else {
    //do nothing
  }
})