javascript 单击地图时关闭信息框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6548225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Close Infobox when clicking on the map
提问by Nyxynyxx
I'm using the Infobox plugin for Google Maps V3 API (http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html)
我正在使用 Google Maps V3 API 的 Infobox 插件(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html)
Is there anyway too close the infobox when the user clicks outside the infobox like on the map?
当用户在地图上的信息框外点击时,信息框是否太近了?
回答by MJB
it's actually way easier if you have your infowindow as a global variable, or at least hold one variable that represents the single infobox you want to add at a convenient place.
如果您将信息窗口作为全局变量,或者至少保存一个变量来表示您想在方便的位置添加的单个信息框,那么实际上会更容易。
edit:just to clarify: it should notbe window.myInfoBox
for example. With global I mean a single point where you reference your infobox
编辑:只是为了澄清:它不应该window.myInfoBox
是例如。对于全局,我的意思是您引用信息框的一个点
google.maps.event.addListener(map, 'click', function() {
if(infowindow){
infowindow.close();
}
});
that's all :-)
就这样 :-)
回答by Eddie
You will want to use addListener()
您将需要使用 addListener()
http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners
http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners
You can adapt the code found here:
您可以修改此处找到的代码:
google.maps.event.addListener(_point.popup, 'domready', function() {
//Have to put this within the domready or else it can't find the div element (it's null until the InfoBox is opened)
$(_point.popup.div_).hover(
function() {
//This is called when the mouse enters the element
},
function() {
//This is called when the mouse leaves the element
_point.popup.close();
}
);
});
Src: Google Maps API v3 Event mouseover with InfoBox plugin
Src: 带有 InfoBox 插件的 Google Maps API v3 事件鼠标悬停
You can detect a map click with this:
您可以通过以下方式检测地图点击:
google.maps.event.addListener(map, 'click', function() {
});
Infobox API: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
信息框 API:http: //google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
回答by Sedat Ba?ar
This maybe useful for you..
这可能对你有用..
var inside = false;
$('#foo').live('mouseenter',function(){
inside=true;
}).live('mouseleave', function(){
inside=false;
});
$("body").mouseup(function(){
if(!inside) $('#foo').remove();
});