Home >Web Front-end >CSS Tutorial >How to use the pointer-events property of CSS to achieve mouse penetration effect

How to use the pointer-events property of CSS to achieve mouse penetration effect

不言
不言Original
2018-06-20 14:44:595483browse

This article mainly introduces how to use the pointer-events attribute of CSS to achieve the mouse penetration effect. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

When pointer After the value of -events is set to none, the browser will not obtain the click event of the mouse on the layer at the current position, causing the effect of mouse penetration! Let's explain the implementation using the pointer-events attribute of CSS. The magical technique of mouse penetration effect

The scope of responsibilities of CSS and JavaScript in modern browsers are becoming increasingly blurred and unclear. For example, the -webkit-touch-callout attribute in CSS can prevent the bubble box from popping up when the user clicks on it in iOS. The style of pointer-events to be discussed in this article is more like JavaScript. It can:
1. Prevent the user’s click action from producing any effect
2. Prevent the display of the default mouse pointer
3. Prevent CSS Changes in hover and active states trigger events
4. Prevent JavaScript click actions from triggering events
One CSS property can do all of so many things!

When using pointer-events:none, it means that it will not capture any clicks, but will just let the event penetrate below it. The code is as follows:

<style>   
 .overlay {   
  pointer-events: none;   
 }   
</style>   
<p id="overlay" class="overlay"></p>

If the value is auto, the effect is the same as if the pointer-events attribute is not defined, and the mouse will not penetrate the current layer. In SVG, this value has the same effect as visiblePainted.

This pointer-events attribute has many attribute values ​​that can be used, but most of them are for SVG: auto, none, visiblePainted*, visibleFill*, visibleStroke*, visible*, painted*, fill*, stroke*, all*, and inherit.

Some things to note about pointer-events:
1. Child elements can declare pointer-events to unlock the mouse event blocking restriction of the parent element.
2. If you set a click event listener for an element, and then you remove the pointer-events style declaration, or change its value to auto, the listener will take effect again. Basically, the listener will respect the pointer-events settings.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About how to use the table-cell attribute in CSS

The above is the detailed content of How to use the pointer-events property of CSS to achieve mouse penetration effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn