有没有办法处理顶点上的悬停事件?在 mxEvents 或任何示例中,我没有看到任何相关内容,例如mouseenter
、mouseleave
、mouseover
等,所以我假设没有。(还有其他狡猾的解决方法吗?)
问问题
2927 次
1 回答
3
hoverstyle示例演示了如何实现这一点。这个与问题相关的特定代码:
// Changes fill color to red on mouseover
graph.addMouseListener(
{
currentState: null,
previousStyle: null,
mouseDown: function(sender, me)
{
if (this.currentState != null)
{
this.dragLeave(me.getEvent(), this.currentState);
this.currentState = null;
}
},
mouseMove: function(sender, me)
{
if (this.currentState != null && me.getState() == this.currentState)
{
return;
}
var tmp = graph.view.getState(me.getCell());
// Ignores everything but vertices
if (graph.isMouseDown || (tmp != null && !
graph.getModel().isVertex(tmp.cell)))
{
tmp = null;
}
if (tmp != this.currentState)
{
if (this.currentState != null)
{
this.dragLeave(me.getEvent(), this.currentState);
}
this.currentState = tmp;
if (this.currentState != null)
{
this.dragEnter(me.getEvent(), this.currentState);
}
}
},
mouseUp: function(sender, me) { },
dragEnter: function(evt, state)
{
if (state != null)
{
this.previousStyle = state.style;
state.style = mxUtils.clone(state.style);
updateStyle(state, true);
state.shape.apply(state);
state.shape.reconfigure();
}
},
dragLeave: function(evt, state)
{
if (state != null)
{
state.style = this.previousStyle;
updateStyle(state, false);
state.shape.apply(state);
state.shape.reconfigure();
}
}
});
于 2014-11-06T09:17:54.370 回答