使用Html5的时候,在Canvas上绘制的东西是不能响应鼠标事件的,但是使用jTopo添加事件非常简单,效果如下:
http://www.jtopo.com/demo/helloworld.html
代码示例:
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");
});
jTopo Canvas 交互示例
本文介绍如何使用jTopo在HTML5 Canvas上添加鼠标事件,包括单击、双击、拖拽等,并提供了具体实现代码。
759

被折叠的 条评论
为什么被折叠?



