D3 Prevent Double Click Zoom [duplicate]

2019-06-27 07:55发布

This question already has an answer here:

I have a D3 Network Graph and I am trying to disable the Double Click zoom function. I have it zooming using:

    var zoom = d3.behavior.zoom().scaleExtent([minZoom, maxZoom]);
    zoom.on("zoom", function() {
            g.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
        });
   svg.call(zoom)

However I cant seem to be able to disable just the Double click zoom. When I use the code below it disables the zoom altogether.

var zoom = d3.behavior.zoom().scaleExtent([minZoom, maxZoom]);
zoom.on("zoom", function() {
            g.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")").on("dblclick.zoom", null);
        });
   svg.call(zoom)

I have also tried calling

    .on("dblclick.zoom", null)

on the svg element by itself and that doesnt work either. Any help would be much appreciated.

1条回答
成全新的幸福
2楼-- · 2019-06-27 08:54

You need to call

    .on("dblclick.zoom", null)

after

    svg.call(zoom)

i.e.

    svg.call(zoom).on("dblclick.zoom", null);
查看更多
登录 后发表回答