简体   繁体   English

如何将焦点返回到具有较低z-index的对象,尝试在地图上创建一系列透明div

[英]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? 如果我有一个包含子div的父div,我可以给父div重点而不隐藏子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. 我正在使用谷歌地图API,并希望在其上面绘制一个透明div的网格,用于插入信息,但是,在我的地图上方的所有这些小div,我无法拖动地图。

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. 我确信我可以使用API​​来做到这一点,但这不是重点,因为无论我在做什么,我都希望这样做。

<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. 我正在使用JQuery并使用.focus()搞砸了但是没有用。

THANKS! 谢谢!

Turns out, you can "passthru" events with jQuery: 事实证明,你可以使用jQuery“passthru”事件:

$(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/ 我把jsFiddle放在一起,随意玩: http//jsfiddle.net/gK6Aa/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM