2
我使用的是this example作为放大我的项目的基础,但我想限制缩放到只有按钮和双击。理想情况下,使用滚轮应该继续向下滚动页面,而不是在鼠标移过时放大svg。任何帮助表示赞赏!d3使用按钮缩放并双击但不使用滚轮缩放
我使用的是this example作为放大我的项目的基础,但我想限制缩放到只有按钮和双击。理想情况下,使用滚轮应该继续向下滚动页面,而不是在鼠标移过时放大svg。任何帮助表示赞赏!d3使用按钮缩放并双击但不使用滚轮缩放
对于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
它仍然可以平移(平移)用鼠标拖动。
你可以做到这一点:
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