score:1

Accepted answer

The zoom events have a transform property:

event.transform - the current zoom transform.

The zoom transform documentation has a nice explanation of how it is internally implemented and why. In short they are implemented as a matrix that can represent a translation and a scale and the transform exposes them via properties. The "zoom level" would then be the scale:

transform.k - the scale factor k.

So a zoom event handler like this should work:

function zoomed(event) {
    console.log(event.transform.k);
}

score:1

Just adding to mmlr's answer

d3.event.transform.k worked for me instead of event.transform.k


Related Query

More Query from same tag