问题
I have a page which has an iframe (containing an interactive map) and a canvas positioned over it by z-depth, to draw as if into the map. So neither are a parent of the other, they're just located in the same place. Both the canvas and the map need to be able to handle the same click events: the map (for interaction with it), and the canvas (to set timeouts for map status changes, for selecting objects, etc).
I'm having trouble figuring out how one is supposed to get all events to flow from one to the next. I tried making one a parent of the other (such as putting the map iframe inside the canvas) so it could flow up the DOM, but then the map doesn't draw. I found this code for using a dispatchEvent to forward copies of events:
Is it possible to selectively pass DOM events through overlapping canvases?
But it seems needlessly complicated, would need to be implemented for every event, and more to the point, didn't work when I tried it.
Surely there's something easy I'm missing... thoughts?
来源:https://stackoverflow.com/questions/46841061/intercepting-all-events-handling-then-letting-them-to-object-underneath