Control z-index in Fabric.js

后端 未结 5 1124
独厮守ぢ
独厮守ぢ 2021-02-05 05:35

In fabricjs, I want to create a scene in which the object under the mouse rises to the top of the scene in z-index, then once the mouse leaves that object, it goes back to the z

5条回答
  •  孤独总比滥情好
    2021-02-05 06:07

    You can use these two functions to get z-index of a fabric object and modify an object's z-index, since there is not specific method to modify z-index by object index :

    fabric.Object.prototype.getZIndex = function() {
        return this.canvas.getObjects().indexOf(this);
    }
    
    fabric.Canvas.prototype.moveToLayer = function(object,position) {
        while(object.getZIndex() > position) {
            this.sendBackwards(object);
        }
    }
    

提交回复
热议问题