Control z-index in Fabric.js

后端 未结 5 1121
独厮守ぢ
独厮守ぢ 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 05:50

    You can modify your _chooseObjectsToRender method to have the following change at the end of it, and you'll be able to achieve css-style zIndexing.

    objsToRender = objsToRender.sort(function(a, b) {
      var sortValue = 0, az = a.zIndex || 0, bz = b.zIndex || 0;
    
      if (az < bz) {
        sortValue = -1;
      }
      else if (az > bz) {
        sortValue = 1;
      }
    
      return sortValue;
    });
    

    https://github.com/fabricjs/fabric.js/pull/5088/files

提交回复
热议问题