zyzo
zyzo

Reputation: 355

SVG elements lose event listeners after transform

When the parent <svg> transform attribute is programmatically changed, I got some weird behaviours of inner SVG elements. Neither css selectors (like :hover) nor javascript listeners (onClick) are working after the change.

Here is an example:

https://jsfiddle.net/ohpaaevt/6/

Could anybody shed some light on this ?

EDIT : I just noticed that applying transform attribute on <svg> doesn't even work on Chrome, only on Firefox. Haven't tested with other browsers.

Upvotes: 0

Views: 216

Answers (1)

Robert Longson
Robert Longson

Reputation: 124249

Transforms on <svg> elements are a new feature of SVG 2 that only Firefox has implemented. In SVG 1.1 the <svg> element does not support having a transform attribute.

SVG 2 is a new specification and is as yet unfinished. Chrome, Firefox and IE Edge have implemented different parts of it.

To work around the lack of suport in Chrome create a <g> child of the <svg> and move all the contents of the <svg> into the <g> element and then transform the <g> element rather than the <svg> element.

Upvotes: 1

Related Questions