Handling click events on z-index#39;d layers(处理 z-indexd 图层上的点击事件)
问题描述
我正在构建的地图应用程序中有 2 个 z-index 图层.当我单击要放大的图层时遇到问题.单击处理程序位于底层 z-index 图层上,我不希望在单击覆盖图层中的控件时触发它.
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.
我遇到的问题是,无论如何都会引发事件,但是当单击顶层上的某些内容时,事件的 originalTarget 属性不是底层中的图像.有没有办法改变这个?
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?
推荐答案
叫做事件冒泡,可以通过event.stopPropagation()
方法来控制(event.cancelBubble()
在 IE 中).您还可以通过从元素上的 onwhatever 属性调用的处理程序返回 true/false 来控制它.这是一个棘手的问题,所以我建议你做一些研究.
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.
信息:cancelBubble, stopPropagation
这篇关于处理 z-index'd 图层上的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:处理 z-index'd 图层上的点击事件
- 失败的 Canvas 360 jquery 插件 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01