I have a problem with absolute positioned div's click. I am developing a website with jquery scrollpath and added extra layers to get parallax effect and top layer covers buttons in main layer and they cant be clicked, hovered, ect.
Here is simple examlple:
<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;
}
}
I need to keep this html structure and ability to click div's in absolute positioned div with lower z-index. Is it possible?
jQuery position() Method The position() method returns the position (relative to its parent element) of the first matched element. This method returns an object with 2 properties; the top and left positions in pixels.
The . position() method allows us to retrieve the current position of an element (specifically its margin box) relative to the offset parent (specifically its padding box, which excludes margins and borders). Contrast this with . offset() , which retrieves the current position relative to the document.
An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).
You can set pointer-events
to none
on the upper element to stop it reacting on mouse events.
pointer-events:none;
JSFIDDLE http://jsfiddle.net/ugGgN/5/
Cross browser support is very good these days: http://caniuse.com/#feat=pointer-events
For more information on pointer-events please see the documentation: https://developer.mozilla.org/en/docs/Web/CSS/pointer-events?v=example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With