在D3中设置后如何删除缩放功能?(How to remove zoom capability after you set it in D3?)
我的力布局中有缩放功能。 我只在ctrl键关闭时调用它,如下所示:
.on("mousedown", function () { if (d3.event.ctrlKey) { d3.select('#selectContainer').call(zoom).on("dblclick.zoom", null); } })这很有效,这是第一次,但显然,如果我按下ctrl而鼠标停止,这将无限期地附加到我的元素。 我的问题是如果我的鼠标停机并且我没有按住ctrl,我该如何删除它?
像这样的东西(显然不起作用):
.on("mousedown", function () { if (d3.event.ctrlKey) { d3.select('#selectContainer').call(zoom).on("dblclick.zoom", null); } else { d3.select('#mainViewerContainerDiv').on("zoom", null); } })I have a zoom functionality in my force layout. I only call it when the ctrl key is down like so :
.on("mousedown", function () { if (d3.event.ctrlKey) { d3.select('#selectContainer').call(zoom).on("dblclick.zoom", null); } })This works great, the first time but obviously, if I press ctrl whilst mouse is down, this will be attached to my element indefinitely. My question is how do I remove this if my mouse is down and I am not holding ctrl ?
Something like this (obviously doesn't work) :
.on("mousedown", function () { if (d3.event.ctrlKey) { d3.select('#selectContainer').call(zoom).on("dblclick.zoom", null); } else { d3.select('#mainViewerContainerDiv').on("zoom", null); } })最满意答案
用.zoom替换zoom
d3.select('#mainViewerContainerDiv').on(".zoom", null);replace zoom with .zoom
d3.select('#mainViewerContainerDiv').on(".zoom", null);更多推荐
发布评论