Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG not recognising pointer-events:none

Tags:

html

css

svg

I have a top layer with a transparent background image set and would like all pointer events to be ignored. So originally I had this set up with <div style="pointer-events"></div> which worked great, but then I find out that IE doesn't support this.

Further reading I find several places that says IE does support <svg> with pointer-events:none, but I can't get it to work (I've never used SVG tags before so I could be doing this all wrong).

Please see this very simplified fiddle of what I'm hoping to achieve. http://jsfiddle.net/AGVTM/

like image 550
dev Avatar asked Dec 20 '12 12:12

dev


2 Answers

The root (top most) <svg> element will not support pointer-events: none. The reason behind this is that it's a possible security exploit, you could cover a Facebook Like button with an SVG and let clicks go through as in this example http://jsfiddle.net/rVxTn/

If the SVG element is not root then clicks should go through. This example should work on IE9 (untested)

http://jsfiddle.net/DLEsn/

However, this doesn't solve your problem, because you cant put HTML elements inside the SVG element.

I've encountered this problem multiple times before, I've had to work around it in different ways. I'd suggest you to open a new question with the actual problem (and possibly screenshots) to see how this can be worked around.

like image 105
methodofaction Avatar answered Sep 22 '22 07:09

methodofaction


Root cause

Absolutely positioned SVGs will not propagate clicks through to HTML elements in IE9.

See this webkit test case discussion: REGRESSION(r66731): pointer-events are broken in some cases, and the corresponding minimal test case. Meaning, interestingly, this bug almost made it in to WebKit, too, but got fixed in time.

In IE 9's case, the results:

IE 9.0.8112.16421 = fails test 1: floating; passes test 2: inline

Workarounds

See this StackOverflow post on simulating pointer-events: none—How to make Internet Explorer emulate pointer-events:none?

They are discussing non-SVG front elements in particular, but the technique of forwarding clicks through to the underlying elements may apply in your case as well.

like image 45
Brian Jordan Avatar answered Sep 24 '22 07:09

Brian Jordan