如何在Graphiti.js中添加矩形上的点击事件
How to add click event on rectangle in Graphiti.js
我想在石墨中的矩形上注册点击事件。我试过这个
var innerrect = new graphiti.shape.basic.Rectangle(100, 20);
innerrect.onClick = function(){
alert("Hi");
}
rect.addFigure(innerrect , new graphiti.layout.locator.BottomLocator(rect));
canvas.addFigure(rect, 100, 100);
但不起作用。请让我知道吧?
像这样创建从矩形继承的自己的形状。这在第一刻看起来有点不舒服,但你写得很正常您自己的形状与许多自定义代码。在这种情况下,装入一个新类是一次性的工作。
请记住,这些例子是一个很好的起点。还有一个关于点击事件监听器的例子。
MyFigure = graphiti.shape.basic.Rectangle.extend({
NAME : "MyFigure",
init : function()
{
this._super();
this.createPort("output");
this.setDimension(30,30);
this.setResizeable(false);
this.value=false;
this.colors={};
this.colors[true]="#00f000";
this.colors[false]="#f00000";
this.setBackgroundColor(this.colors[this.value]);
},
/**
* @method
* Change the color and the internal value of the figure.
* Post the new value to related input ports.
*
*/
onClick: function(){
this.value = !this.value;
this.setBackgroundColor(this.colors[this.value]);
var connections = this.getOutputPort(0).getConnections();
connections.each($.proxy(function(i, conn){
var targetPort = conn.getTarget();
targetPort.setValue(this.value);
conn.setColor(this.getBackgroundColor());
},this));
}
});
相关文章:
- 将单击事件添加到数据表
- 将单击事件添加到附加的项目中
- 使用引导事件添加动画
- 如何将单击事件添加到JQuery中动态添加的元素中
- 如何在jQuery中将事件添加到新生儿元素中
- JQuery将侦听事件添加到.rezable(),然后附加DIV's
- jQuery:使用实时事件添加tabindex属性
- 将单击事件添加到显示字段
- 如何将事件添加到jQuery's on()回调
- 将此事件添加到工具栏
- TinyMCE 将另一个事件添加到粗体和斜体按钮
- 当用户在输入字段事件中输入内容时,为该字段事件添加动画占位符
- 使用 JQuery 将 onclick 事件添加到动态创建的定位点
- Raphaeljs 将点击事件添加到饼图的一部分
- 将事件添加到网格的coffeescript实现中
- 将事件添加到谷歌地图标记
- Javascript:将onkeydown事件添加到prompt()中
- 如何将onclick事件添加到joint.js元素中
- 角度指令:绑定'鼠标悬停'事件添加到元素
- 将事件添加到涉及for()的索引中的多个子节点