The key is to talk about the scaling behavior that you reset and scale. To do this, simply store it in a variable and set the values accordingly when you set the transform SVG attribute.
var zoom = d3.behavior.zoom(); svg.call(zoom.on("zoom", redraw)); // ... .on("click", function () { counter++; canvas .transition() .duration(1000) .attr('transform', "translate(" + (offset * counter) + ",0)"); zoom.scale(1); zoom.translate([offset * counter, 0]); drawBox(x, y); });
Updated jsfiddle here .
source share