簡體   English   中英

如果通過代碼移動 FabricJS object,鼠標選擇似乎不起作用

[英]If a FabricJS object is moved by code, the mouse selection does not appear to work

If I move an object by code, when the mouse is used to select the object, the selection seems to select the object based on its old position. In the example below, the object can be selected by its old position, and not in its當前 position。

我做錯了什么,或者這是 FabricJS 中的錯誤?

var canvas = window._canvas = new fabric.Canvas('c');

var rect = new fabric.Rect({
    left: 50,
    top: 50,
    width: 50,
    height: 50,
    fill: 'rgba(255,0,0,0.5)',
});

canvas.add(rect);

var rect_json = rect.toJSON();
rect_json.left += 100;
rect.set(rect_json);

查看此小提琴以查看其實際效果。

您需要調用setCoords才能重新計算控件位置。

請檢查此鏈接何時調用 setCoords

var canvas = window._canvas = new fabric.Canvas('c');

var rect = new fabric.Rect({
    left: 50,
    top: 50,
    width: 50,
    height: 50,
    fill: 'rgba(255,0,0,0.5)',
});

canvas.add(rect);

rect.set({ left: 300 }).setCoords()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM