使用jTopo給Html5 Canva中繪制的元素添加鼠標(biāo)事件

字號:


    使用Html5的時候,在Canvas上繪制的東西是不能相應(yīng)鼠標(biāo)事件的,但是使用jTopo添加事件非常簡單,效果如下:
    代碼示例:
    代碼如下:
    var node = new JTopo.Node("Hello");
    node.setLocation(409, 269);
    node.mousedown(function(event){
    if(event.button == 2){
    node.text = '按下右鍵';
    }else if(event.button == 1){
    node.text = '按下中鍵';
    }else if(event.button == 0){
    node.text = '按下左鍵';
    }
    });
    node.mouseup(function(event){
    if(event.button == 2){
    node.text = '松開右鍵';
    }else if(event.button == 1){
    node.text = '松開中鍵';
    }else if(event.button == 0){
    node.text = '松開左鍵';
    }
    });
    node.click(function(event){
    console.log("單擊");
    });
    node.dbclick(function(event){
    console.log("雙擊");
    });
    node.mousedrag(function(event){
    console.log("拖拽");
    });
    node.mouseover(function(event){
    console.log("mouseover");
    });
    node.mousemove(function(event){
    console.log("mousemove");
    });
    node.mouseout(function(event){
    console.log("mouseout");
    });