如何禁用pan d3.behavior.zoom? [英] How to disable pan for d3.behavior.zoom?
问题描述
这个问题与这个问题非常相似,但我仍然不能确定是否可以使用d3.behavior.zoom但没有平移能力。换句话说,我只是想使用轮只放大/缩小。
This question looks quite similar to this one, but I am still not able to figure out whether it is possible to use d3.behavior.zoom but without the pan ability. In other words I just want to zoom-in/out using the wheel only.
这样做的原因是我想要刷可缩放区域。
The reason for this is that I want to be able to brush on the "zoomable" area.
谢谢!
推荐答案
缩放行为:
var zoom = d3.behavior.zoom().on('zoom', update);
当将缩放行为应用于选择时,可以取消注册它在内部使用的事件侦听器检测和响应某些交互。在你的情况下,你想做这样的事情:
When you apply the zoom behavior to a selection, you can unregister the event listeners that it uses internally to detect and respond to certain interactions. In your case, you'd want to do something like this:
selection.call(zoom)
.on("mousedown.zoom", null)
.on("touchstart.zoom", null)
.on("touchmove.zoom", null)
.on("touchend.zoom", null);
我不确定要删除触摸事件。这样做可能会消除双击缩放。你应该尝试这些。
I'm not sure you want to remove the touch events. Doing so might eliminate double tap zooming. You should experiment with those.
这篇关于如何禁用pan d3.behavior.zoom?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!