2016-06-07 230 views

回答

2

对于D3 4.0,这里有两种方法,以防止D3变焦从响应滚轮事件。

答:

zoom.filter(function() { return !event.button && event.type !== 'wheel'; }) 
// the `!event.button` expression is from the default filter, according to 
// doc for zoom.filter([filter]) 

B:

svg.on("wheel.zoom", null); 
// according to doc for zoom(selection): Internally, the zoom behavior   
// uses selection.on to bind the necessary event listeners for zooming. 
// The listeners use the name .zoom 

它仍然可以平移(平移)用鼠标拖动。

1

你可以做到这一点:

var svg = d3.select("body").select("svg") 
    .attr("width", width) 
    .attr("height", height) 
    .append("g") 
    //.call(zoom) //remove the zoom listener from the group. 
    .append("g"); 

下一页附上doublclick听众的圆圈和缩放矩形。

d3.selectAll("rect").on('dblclick', zoomClick) 
d3.selectAll("circle").on('dblclick', zoomClick) 

工作代码here