2013-04-07 172 views
0

我激活和關閉變焦的行爲出現在http://bl.ocks.org/benzguo/4370043時:D3-JS鼠標滾輪的問題來啓用和停用縮放行爲

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

此代碼將禁用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

您可能想要專門禁用縮放滾輪事件。

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

我使用3.3.2,這需要稍作修改。你必須使用(「wheel.zoom」,null) – 2014-01-10 08:13:48

相關問題