处理z-index'd图层上的点击事件 [英] Handling click events on z-index'd layers

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

问题描述

我正在建立的地图应用程序中有2个z-index层。当我点击图层进行放大时,我有一个问题。点击处理程序在底层的z-index层上,当单击上覆层中的控件时,我不希望它触发。



我遇到的问题是事件不管是什么,但是事件的originalTarget属性不是底层中的图像,而顶层的东西是点击。有没有改变这个?

解决方案

它被称为事件冒泡,你可以用 IE中的event.stopPropagation()方法( event.cancelBubble())。您还可以通过从onwhatever属性调用的处理程序返回true / false来控制它。这是一个棘手的问题,所以我建议你做一些研究



信息: cancelBubble stopPropagation


I have 2 z-index layers in a map application I'm building. I have a problem when I click on the layers to zoom in. The click handler is on the underlying z-index layer and I don't want it to fire when a control in the overlying layer is clicked.

The problem i have is that the event gets raised no matter what but the originalTarget property of the event is not the image in the underlying layer when something on the top layer is clicked. Is there anyway to change this?

解决方案

It's called event-bubbling, and you can control it with the event.stopPropagation() method (event.cancelBubble() in IE). You can also control it by returning true/false from handlers called by onwhatever attributes on elements. It's a tricky subject so I suggest you do some research.

Info: cancelBubble, stopPropagation

这篇关于处理z-index'd图层上的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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