gpt4 book ai didi

javascript - jquery绝对定位元素点击

转载 作者:数据小太阳 更新时间:2023-10-29 05:48:20 24 4
gpt4 key购买 nike

我对绝对定位的 div 的点击有疑问。我正在开发一个带有 jquery 滚动路径的网站,并添加了额外的层以获得视差效果,顶层覆盖了主层中的按钮,它们无法被点击、悬停等。

Here是简单的例子:

<div class="body">
<div class="a"></div>
<div class="b">
<div class="element first">First</div>
<div class="element second">Second</div>
</div>
</div>

.body {
position relative;
}
.a {
position: absolute;
left: 20px;
top: 20px;
width: 300px;
height: 600px;
background: rgba(0,0,0,0.5);
z-index: 2;
}
.b {
position: absolute;
left: 40px;
top: 40px;
width: 260px;
height: 300px;
background: blue;
z-index: 1;
}
.b .element {
position: absolute;
width: 50px;
height: 50px;
background: red;
}
.b .element.first {
top: 50px;
left: 50px;
}
.b .element.second {
bottom: 50px;
right: 50px;
}
}

我需要保留此 html 结构和在具有较低 z-index 的绝对定位 div 中单击 div 的能力。是否可以?

最佳答案

您可以将上部元素的 pointer-events 设置为 none 以停止它对鼠标事件使用react。

pointer-events:none;

JSFIDDLE http://jsfiddle.net/ugGgN/5/

现在跨浏览器支持非常好:http://caniuse.com/#feat=pointer-events

有关指针事件的更多信息,请参阅文档:https://developer.mozilla.org/en/docs/Web/CSS/pointer-events?v=example

关于javascript - jquery绝对定位元素点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16884571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com