I have an square image depicting a car on a transparent background. I want to be able to click on car, yet when I click on it’s transparent background I’d like the click to go through the image and trigger on the underlying DOM element (or, specifically, other image).
Can that be achieved somehow?
That’s quite complex, but can be achieved by combining Pointer events to allow for the
clickto bubble up the DOM (reaching theimgparent container), and a faux Canvas on top to detect a transparent pixel (which will be used as a flag to activate the event delegation).Pointer events were derived from the SVG model to allow for event delegation across layers. Note that they’re currently not supported on IE and Opera.
Related Posts:
Demo:
pointer-eventson jsFiddleReference:
pointer-eventson Mozilla Developer NetworkFurther Read: