z-index 和 Javascript 事件
我有几个彼此重叠的 div,具有不同的 z-index 值。
浏览器的默认行为似乎是触发绑定到最顶部 z-index div 的事件。即,每个 div 都有多个 onclick
,但当单击该区域时,只有顶部的一个被触发。
有没有一种方法可以触发附加到所有 div 的事件,无论每个 div 的 z 索引是什么,只要操作“超过”该 div 而不考虑 z 索引?
I have a couple of divs overlaid on each other 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. I.e. I have multiple onclick
s 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该事件实际上不会发生在被另一个元素遮挡的元素上,除非另一个元素包含在第一个元素中,然后它会冒泡。我能想到的实现您想要的效果的唯一方法是遍历所有潜在元素,看看其中是否有任何元素包含单击发生的点并触发对该元素的单击(如果它不是当前元素) )。
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).
如果您使用的是 javaScript 框架,则可能会包含事件冒泡。 (我确信 ExtJS 具有这种事件功能。)
If you are using an javaScript framework event bubbling might be included. (ExtJS I know for sure has this kind of event feature.)