andrii
andrii

Reputation: 1388

Multiple HTML5 canvas overlaying

Is it possible to create some stack of transparent HTML5 canvases with event propagation?

For instance, I have a background canvas with drawn image on it with some attached click handler. After, I want to add another one canvas over the background canvas with exactly same size, also it has transparent zones. The question is, will the click handler of background canvas be fired if I click on it over the top layer?

Upvotes: 1

Views: 709

Answers (1)

Simon Sarris
Simon Sarris

Reputation: 63802

will the click handler of background canvas be fired if I click on it over the top layer?

No it will not. The canvas blocks events from things behind it.

Generally you have two options: Put events on each canvas and make a system of letting them "fall through" if nothing happens on the first canvas, or putting events only on the topmost canvas and using those one events to do operations concerning all canvases.

I suggest the second approach. Keep all the events on only the topmost canvas.

Upvotes: 1

Related Questions