[英]Disable group selection in Fabric.js
如何在 Fabric.js 中禁用組選擇並一次選擇一個對象? 對於組選擇,我的意思是使用例如選擇多個對象。 Shift + 單擊。
你可以很容易地做到這一點
canvas.selection = false; // disable group selection
如果你想在單個對象上使用它
rect.set('selectable', false); // make object unselectable
通過選擇偵聽器畫布方法禁用組選擇(在我看來是最好的方法)
canvas.on('selection:created', (e) => {
if(e.target.type === 'activeSelection') {
canvas.discardActiveObject();
} else {
//do nothing
}
})
@CQ Smooth 的回答接近我的要求,謝謝。 但是我需要在您首先選擇一個對象時觸發該事件,然后通過 shift+click 添加另一個對象:
canvas.on({
'selection:updated': e => {
const activeSelection = e.target
if (activeSelection) {
canvas.discardActiveObject();
}
}
})
您可以在以下位置查看解決方案: https : //app.collagemaker.uk/create
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.