在画布中隐藏对象

Tru*_*ani 5 javascript asp.net-mvc canvas html5-canvas html2canvas

我想知道,是否可以使用Fabric JS在画布中隐藏文本对象?
我不想删除对象,因为我需要进一步使用它,所以只想隐藏它即可。我搜索了很多,但没有任何效果。这是我的fabric js代码。

var text = new fabric.Text("test", {
                    fontFamily: 'Times new roman',
                    fontSize: fabric.util.parseUnit(fontSize),
                    left: (startPosition.x + pointer.x) / 2,
                    top: ((startPosition.y + pointer.y) / 2) + 10,
                    slope: ((startPosition.y - pointer.y) / (startPosition.x - pointer.x)),
                    originX: 'center',
                    originY: 'center',
                });

canvas.add(text);
//canvas.getObjects(text).style.display = "none";
//text.prop.hide();
//text.hide = function () {
//text.set({
//        css: {"display":"none"},
//        selectable: false
//    });
//};
Run Code Online (Sandbox Code Playgroud)

所有建议均为例外。

Cle*_*ath -1

使用查询选择器隐藏对象。

// Pass the appropriate values to query selector of the canvas which we need to hide, In your code snippet you have given it as center, replace it with numeric values 

var query="canvas[x= fill the value of x ][y= fill the value of y][height= 'give the height'][width='give the width']";

// Finding the canvas
var canvas=document.querySelector(query);

// Hide the canvas
canvas.style.display="none";
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助