svgdotjs / svg.panzoom.js

A plugin for svg.js which enables panzoom for viewbox elements
MIT License
93 stars 54 forks source link

Function wheelZoom dispatches the 'zoom' event too early #74

Open burgrmikulas opened 4 years ago

burgrmikulas commented 4 years ago

The 'zoom' event is being dispatched by the wheelZoom function before the actual zooming happens. I would like to hook to this event and be able to read the new viewport to adjust other elements in the SVG (my use case is keeping vector-effect-like stroke of a line, i.e. same pixels width whatever zoom level I am in).

If dispatching this event cannot be done later, I suggest dispatching another event (e.g. 'afterZoom') at the very end of this function. This is the workaround I have put in place and seems to be working perfectly.

Many thanks for any suggestions/actions on this.

Fuzzyma commented 4 years ago

That might be useful. What I did, was just using setTimeout(fn, 0) in the zoom event to make the zoom happen first and run my code afterwards but I see that a seperate event might be cleaner. The reason the event comes first is because it is cancelable. So you actually can prevent the zoom from happening.