如何禁用 d3.behavior.zoom 的平移? [英] How to disable pan for d3.behavior.zoom?

查看:24
本文介绍了如何禁用 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.

谢谢!

推荐答案

假设你已经定义了一个缩放行为:

Say you've defined a zoom behavior:

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.

这篇关于如何禁用 d3.behavior.zoom 的平移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆