Description

Change or get the index of the item. The index used to define the superposition. By default, the first element has index 0. If an item is created at the same level, it will overlay the previous element and its index will be 1. First, assign the element to a parent before using the method

Usage

Parameters

  • index {Integer|Element} optional

    (optional) If the value is not specified, the current index of the element is returned. If the value is negative, you change the index from the end. If the value is an element, that element is placed after the element indicated

Returns

Integer|CanvasEngine.Element

Example

In method ready

var el1 = this.createElement(),
    el2 = this.createElement(),
    el3 = this.createElement();

stage.append(el1, el2, el3);

                // Original order : el1 ; el2 ; el3
el1.zIndex(1);  // New order : el2 ; el1 ; el3
el2.zIndex(-1); // New order : el1 ; el3 ; el2
console.log(el3.zIndex()); // return "1"

el1.zIndex(el2); // New order : el3 ; el2 ; el1

Discussion