我想在 d3.js 强制布局中启用拖动。当拖动一个圆圈并释放鼠标按钮时,我想通过回调调用特定的函数,如下所示:
this.force = d3.layout.force()
.nodes(this.nodes)
.size([this.width, this.height]);
// enable dragging
this.circle
.call(this.force.drag)
.on("dragend", function() {
console.log("You should see this, when releasing a circle.");
})
.on("mouseup.drag",function(d,i) {
console.log("Or see this.");
});
不幸的是,force.drag 处理程序从未完全触发/消耗该事件。
那么如何在拖动结束时在 d3 力布局中执行给定的回调函数呢?
你没有打电话给"dragend"
事件于this.force.drag
这里。
这也取决于你如何定义this.force.drag
.
这应该适合你
myCustomDrag = d3.behavior.drag()
.on("dragstart", function(d,i){
//do something when drag has just started
})
.on("drag", function(d,i){
//do something while dragging
})
.on("dragend", function(d,i){
//do something just after drag has ended
});
在上面的代码中,只需使用call(myCustomDrag)
在您希望出现此拖动行为的元素(此处为圆圈)上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)