在D3中设置后如何删除缩放功能?(How to remove zoom capability after you set it in D3?)

编程入门 行业动态 更新时间:2024-10-19 11:53:25
在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);

更多推荐

本文发布于:2023-08-02 18:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   功能   remove   set   capability

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!