z-index和javascript事件 [英] z-index and javascript events

查看:100
本文介绍了z-index和javascript事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



浏览器的默认行为似乎是绑定到顶级域名的事件,大多数z-index div被解雇。也就是说,我有多个onclicks每个div一个,但只有顶部的一个点击时触发区域。



有没有一种方法来触发附加到所有div的事件no问题是什么z-index是每一个,只要行动是'超过'div而不考虑z-index?

解决方案

事件实际上不会发生在被另一个元素遮蔽的元素上,除非另一个元素被包含在第一个元素中,那么它会起泡。我能想到的唯一方法就是通过所有可能的元素,看看它们中是否包含发生点击的点,并触发该元素的点击(如果它不是当前元素的点击) )。


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?

解决方案

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

这篇关于z-index和javascript事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆