4
在D3中,平移鍵在(左鍵或右鍵單擊)+拖動中都可以工作。 但是,在我的情況下,我想保留(左鍵單擊並拖動)其他操作,同時(右鍵單擊並拖動)進行平移。如何禁用d3中的左鍵單擊平移
如何禁用左鍵單擊平移?
謝謝。
在D3中,平移鍵在(左鍵或右鍵單擊)+拖動中都可以工作。 但是,在我的情況下,我想保留(左鍵單擊並拖動)其他操作,同時(右鍵單擊並拖動)進行平移。如何禁用d3中的左鍵單擊平移
如何禁用左鍵單擊平移?
謝謝。
我解決了這個問題,如下所示:
function doDrag() {
if (d3.event.button === 0) {
d3.event.stopImmediatePropagation();
}
//other drag work
}
我呼籲mousedown事件此功能。
在您處理拖動的功能中添加鼠標向下的檢查。
function doDrag(){
if(d3.event.sourceEvent.button == 0){
d3.event.stopImmediatePropagation();
return;
}
//other drag work
}
希望這會有所幫助!
謝謝。你的帖子引導我到實際的解決方案: 函數doDrag(){ if(d3.event.button === 0){ d3.event.stopImmediatePropagation(); } //其他拖動工作 } – Pixelord
謝謝更新了我的答案! – Cyril