Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolutely Positioned DIV with a High Z-Index Is Blocking Click Events Below it

Here is what I am trying to do:

Create a global "gesture container" that is absolutely positioned, width and height 100%, and a z-index that is higher than all other elements in the document.

Here is my problem: When I create this container, my absolutely positioned element is blocking the click events that are bound to everything that is below it.

$(document).ready(function() {
    $(document).on('click touchstart', '.block', function() {
        var $this = $(this);

        if(!$this.hasClass("disabled")){
            $this.addClass("disabled")
            $this.openPopUp();
        }
        return false;           
    });
});

Notice I am using the new .on() call from jQuery 1.7.2 which I have set up to function the same way as .live().

Why is my element not accepting my click? Looks like my gesture area is blocking it, but is there a way around that?

like image 450
Alex Avatar asked May 25 '12 20:05

Alex


People also ask

Can I use Z index with position absolute?

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).

How do I fix Z index in CSS?

In Summary To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

Why Z Index property is not working?

You set z-index on a static element By default, every element has a position of static. z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.

How do you use Z index without absolute positioning?

Yes: use position:relative; z-index:10 . z-index has no effect for position:static (the default). Show activity on this post. I know Phrogz' answer has been accepted already, and a good answer it is, but just for the record: you don't always need z-index .


2 Answers

Solution one. CSS. Set pointer-events: none;, but this only works for Firefox, Chrome and Safari.

Solution two. JavaScript. http://www.vinylfox.com/forwarding-mouse-events-through-layers/

like image 196
Ana Avatar answered Sep 30 '22 02:09

Ana


I don't think you can override that. Basically that is how events works, that is why you can show a dialog box on the centre of the screen and click in it without firing the same events on elements below that dialog box.

You can make similar elements on that higher elements but this would be looking like click-jacking and some browser addons may mark your site as a potential risk

Here is similar discussion on this topic: HTML "overlay" which allows clicks to fall through to elements behind it

like image 23
Zefiryn Avatar answered Sep 30 '22 04:09

Zefiryn