通过绝对定位元素传递鼠标事件 [英] Pass mouse events through absolutely-positioned element

查看:31
本文介绍了通过绝对定位元素传递鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个元素上捕获鼠标事件,而另一个绝对定位的元素位于该元素之上.

I'm attempting to capture mouse events on an element with another absolutely-positioned element on top of it.

现在,绝对定位元素上的事件击中它并向上冒泡到其父级,但我希望它对这些鼠标事件透明"并将它们转发到它后面的任何事件.我应该如何实施?

Right now, events on the absolutely-positioned element hit it and bubble up to its parent, but I want it to be "transparent" to these mouse events and forward them on to whatever is behind it. How should I implement this?

推荐答案

pointer-events: none;

是使事件通过"的 CSS 属性应用该属性的 HTML 元素.它使事件发生在元素下方"上.

Is a CSS property that makes events "pass through" the HTML-element to which the property is applied. It makes the event occur on the element "below".

查看详情:https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

几乎所有浏览器都支持,包括IE11;05/'21 的全球支持率约为 98.2%):http://caniuse.com/#feat=指针事件(感谢@s4y 在评论中提供链接).

It is supported by almost all browsers, including IE11; global support was ~98.2% in 05/'21): http://caniuse.com/#feat=pointer-events (thanks to @s4y for providing the link in the comments).

这篇关于通过绝对定位元素传递鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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