z-index and javascript events

做~自己de王妃 提交于 2019-12-01 15:18:04

问题


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?


回答1:


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).




回答2:


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



来源:https://stackoverflow.com/questions/1936735/z-index-and-javascript-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!