How to solve the click event that the slot blocks the box below?

If the slot (slot) blocks the click event of the box below, you can try to use the pointer-events property in CSS to solve this problem. The pointer-events property controls whether the element responds to mouse events.
In this case, you can set the pointer-events property of the slot element to none so that it does not respond to mouse events, allowing the underlying box to receive click events.

Here's an example of how to resolve click events where a slot blocks a box below by using the pointer-events property:

//html
<div class="container">
  <div class="box box1">Box 1</div>
  <div class="slot"></div>
  <div class="box box2">Box 2</div>
</div>
//css
.container {
    
    
  position: relative;
}

.box {
    
    
  position: absolute;
  width: 200px;
  height: 200px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
}

.box1 {
    
    
  top: 100px;
  left: 100px;
  z-index: 2;
}

.slot {
    
    
  position: absolute;
  top: 120px;
  left: 120px;
  width: 100px;
  height: 100px;
  background-color: #ddd;
  pointer-events: none; /* 设置为none,不响应鼠标事件 */
}

.box2 {
    
    
  top: 150px;
  left: 150px;
  z-index: 1;
}

In the example above, we placed two boxes (.box1 and .box2) inside the container, and a slot element (.slot) above .box1. By setting the pointer-events property of a slot element to none, it will not respond to mouse events.

In this way, even if the slot blocks the lower box, the lower box can still receive click events. You can bind a click event handler on the second box (.box2) to perform the appropriate action when it is clicked.

Please note that the pointer-events attribute has certain requirements for browser compatibility. When using it, make sure to take into account the compatibility requirements of the target browsers and test appropriately.

Guess you like

Origin blog.csdn.net/z2000ky/article/details/130882731