Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set zindex in konva.js?

Tags:

konvajs

I have a problem with the Zindex in konva.js. After I added everything to the layer I am trying to assign a property to a node for each element separately. But it does not work. For example

for(let i = 0; i<=this.layer['children']; i++){
    this.layer['children'][i].setZIndex(someInt);
}

How can i set zindex for all elements in layer?

like image 652
Kamron Maxmudov Avatar asked Oct 15 '25 15:10

Kamron Maxmudov


2 Answers

zIndex in Konva is just index of the element in an array of children of the parent element. So you can't set any number to it and it can not be bigger than children.length - 1.

like image 98
lavrton Avatar answered Oct 18 '25 14:10

lavrton


If you would prefer to be able to set the render order of nodes using arbitrary numbers (like CSS, or how it works in most game engines, etc), you can use this fork of Konva. Alternatively, you could also grab & apply just the rejected pull request for this feature if you already have a customized Konva version.

The new feature works by adding a zOrder property to all Nodes, and a special kind of group AbsoluteRenderOrderGroup that reads and understands this property for all children.

like image 37
Skye Avatar answered Oct 18 '25 15:10

Skye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!