如何禁用选择自由绘制Fabric.js [英] How to disable selection freedrawing fabricjs

查看:91
本文介绍了如何禁用选择自由绘制Fabric.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FabricJs中使用FreeDrawing绘制某些东西之后,您可以选择绘制的内容并将其移动.有没有办法禁用此选择?

After you draw something with FreeDrawing in FabricJs, you are able to select what was drawn and move it. Is there a way to disable this selection?

推荐答案

如果画布上不需要任何交互性,则可以使用 StaticCanvas

In case you don't need any interactivity on your canvas, you can use StaticCanvas

var canvas = this.__canvas = new fabric.StaticCanvas('c');

或者,如果您只想禁用对特定对象(即最后的笔刷笔触)的选择,则可以在每次创建笔触时尝试调用以下代码:

Or, in case you want to disable selection only for specific objects, i.e. the last brush stroke, you can try calling the following code every time the stroke is created:

canvas.item(0).selectable = false;
canvas.renderAll();


如果您需要与其他对象进行交互,则还可以在画布初始化后立即定义


If you need interactivity for other objects, you can also define this right after canvas initialization

fabric.Object.prototype.selectable = false;

所有新对象都是不可选择的,除非您要创建可选择对象时另行指定

all new objects will be non-selectable, unless you specify otherwise when you want to create a selectable object

var text = new fabric.Text('Honey,\nI\'m subtle', {
    fontSize: 250,
    left: 50,
    top: 0,
    selectable: true // make this object selectable
});
canvas.add(text);

这篇关于如何禁用选择自由绘制Fabric.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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