Try this instead:
svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "grey")
.call(d3.behavior.zoom()
.on("zoom", function() {
svg.attr("transform", "translate(" + d3.event.translate +
")scale(" + d3.event.scale + ")");
}));
svg = svg.append("g");
The problem with your version is that your zoom behaviour was bound to the
<svg> element. This means that it will receive any "mousedown" events
propagated from child elements. The drag behaviour doesn't prevent mousedown
from being propagated (and I don't think it should, because you may want to
handle this event for some reason). So the solution is to only listen for
mousedown (via the zoom behaviour) on the area that you wish to make zoomable
i.e. the background rectangle in your case.
Bind the zoom behaviour to this rectangle and it works as expected.
--
Jason Davies, http://www.jasondavies.com/