激活和取消激活缩放行为时d3-js鼠标滚轮问题

时间:2013-04-07 22:14:56

标签: javascript svg d3.js zoom mousewheel

我激活和停用缩放行为,如http://bl.ocks.org/benzguo/4370043

中所示
var zoom = d3.behavior.zoom().on("zoom", rescale)
// after adding the handler, the mouse wheel will still scroll the page

// activate
svg_g_element.call(zoom)
// now, the mouse wheel zoom

// desactivate
svg_g_element.call(d3.behavior.zoom().on("zoom")    

// now, the mouse wheel will neither zoom nor scroll while over the svg_g_element

如何建立滚动页面的默认鼠标滚轮行为?或者示例中显示的方式不是停用缩放行为的最佳方法吗?

2 个答案:

答案 0 :(得分:2)

此代码也将禁用Firefox上的鼠标滚轮缩放。

svg_g_element
      .on("mousewheel.zoom", null)
      .on("DOMMouseScroll.zoom", null) // disables older versions of Firefox
      .on("wheel.zoom", null) // disables newer versions of Firefox

答案 1 :(得分:1)

您可能希望特别禁用缩放鼠标滚轮事件。

svg_g_element.on("mousewheel.zoom", null);