How to identify the type of a selected object?

前端 未结 4 1316
故里飘歌
故里飘歌 2021-02-12 11:13

I am placing Text, Image and Shapes on canvas using Fabric.js. I have made Three different Edit-Panels for all three. When user select text I want to show text panel. like wise

4条回答
  •  别跟我提以往
    2021-02-12 11:56

    Try isType()

    Sample function for getting selected objects

    function onObjectSelected(o){
        //activeObject = canvas.getActiveObject()
        activeObject = o.target;
    
        if(activeObject.isType('text')){
           //display text logic
        }
        else if(activeObject.isType('image')){
          //display image
        }
        else if( activeObject.isType('xyz')){
          //display shape logic
        }
    }
    
    canvas.on('object:selected', onObjectSelected);
    

提交回复
热议问题