3
我想要在d3.js強制佈局中啓用拖動。當拖動一個圓圈,然後鬆開鼠標按鈕,我想通過回調來調用特定的功能,如:在強制佈局上拖動可以防止其他mouseup偵聽器
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強制佈局中執行給定的回調函數?
'this.force.drag'來自d3庫,它不是用戶自定義的。 [這個答案](http://stackoverflow.com/a/11867374/295686)會接近,但我無法得到它的工作,這就是爲什麼我一直在尋找。 – mlhDev
是的,它來自d3庫,但您始終可以覆蓋它。 您提到的答案只是編寫上述代碼的另一種方式。 – arunkjn
我最終做了或多或少的你在這裏。 +1 – mlhDev