z-index and javascript events

2019-02-21 17:18发布

So I have a couple of divs overlaid on eachother with differing z-index values.

The default behaviour for browsers seems to be the event bound to the top-most z-index div gets fired. Ie I have multiple onclicks one for each div but only the top one is fired when the area is clicked.

Is there a way to fire the events attached to all divs no matter what the z-index of each is, so long as the action is 'over' that div without regard to z-index?

2条回答
We Are One
2楼-- · 2019-02-21 17:59

The event doesn't actually occur on the element that is obscured by another unless the other element is contained in the first, then it will bubble up. The only way that I can think of to achieve what you want is to go through all of the potential elements and see if any of them contain the point at which the click occurred and trigger a click on that element (if it's not the current one).

查看更多
放我归山
3楼-- · 2019-02-21 17:59

If you are using an javaScript framework event bubbling might be included. (ExtJS I know for sure has this kind of event feature.)

查看更多
登录 后发表回答