Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I give focus back to object with lower z-index, trying to create a series of transparent divs on top of a map

If I have a parent div that contains a child div on top of it, can I give the parent div the focus without hiding the child div?

I am using Google Maps API and would like to draw a grid of transparent divs on top of it for inserting information, however, with all of those little divs on top of my map, I cannot drag the map.

I'm sure I can do it using the API but that's sort of beside the point, because I would like to do this regardless of what I'm working on top of.

<div style="position: relative; width: 100px; height: 100px;" id="wanttofocus">
    <div style="position: absolute; width: 100px; height: 100px;" 
    id="want_to_see_but_dont_want_to_focus_on">Some overlay information</div>
</div>

I am using JQuery and messed around with .focus() but that didn't work out.

THANKS!

like image 854
durangotango Avatar asked Sep 28 '11 14:09

durangotango


People also ask

Does opacity affect Z index?

If an element with opacity less than 1 is positioned, the 'z-index' property applies as described in [CSS21], except that 'auto' is treated as '0' since a new stacking context is always created.

How do I fix a Z index problem?

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.

How do you make a DIV appear on top of everything else on the screen?

Set the DIV's z-index to one larger than the other DIVs. You'll also need to make sure the DIV has a position other than static set on it, too. position relative and z index set to 999999999999999999999999999999999999999999999999999.


1 Answers

Turns out, you can "passthru" events with jQuery:

$(document).ready(function(){
    $('#want_to_see_but_dont_want_to_focus_on').bind('mousemove mousedown mouseup', function(e){
        $("#wanttofocus").trigger(e); // passing thru the event
    });

    $('#wanttofocus').bind('mousemove mousedown mouseup', function(e){
        $('.status').html(e.type + ' ' + e.pageX + ' ' + e.pageY);
    });
});

I've thrown together a jsFiddle, feel free to play: http://jsfiddle.net/gK6Aa/

like image 134
vzwick Avatar answered Nov 07 '22 07:11

vzwick