我正在使用Google地圖V3 API的信息框插件(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference .html)單擊地圖時關閉信息框
當用戶在地圖上點擊信息框之外的地方時,反正有太接近的信息框嗎?
我正在使用Google地圖V3 API的信息框插件(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference .html)單擊地圖時關閉信息框
當用戶在地圖上點擊信息框之外的地方時,反正有太接近的信息框嗎?
您將要使用addListener()
http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners
可以適應代碼在這裏找到:
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
可以偵測到地圖上點擊此:
google.maps.event.addListener(map, 'click', function() {
});
信息框API: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
這也許對你有用..
var inside = false;
$('#foo').live('mouseenter',function(){
inside=true;
}).live('mouseleave', function(){
inside=false;
});
$("body").mouseup(function(){
if(!inside) $('#foo').remove();
});
我應該使用'.live()從jQuery的單點'或使用'google.maps.event.addListener( )'從谷歌地圖API?兩個聽衆是一樣的嗎? – Nyxynyxx
.live()是jquery的func,所以我認爲你可以像這樣使用,如果你導入最後的jquery js文件.. –
它實際上是比較容易的方式,如果你有你的信息窗口爲全局變量,或至少保持一個變量代表您想在方便的地方添加的單個信息框。
編輯:我只想澄清:應該不是window.myInfoBox
例如。隨着全球我的意思是,你引用您的信息框
google.maps.event.addListener(map, 'click', function() {
if(infowindow){
infowindow.close();
}
});
這一切:-)
是否可以添加一個監聽器到我的網頁上的所有(10)標記?或者我必須單獨添加每一個? – Nyxynyxx
上面的代碼應該適用於所有的標記..而不是使用.hover,使用.live('點擊'... 編輯:只需注意你想要它,當你點擊地圖,你需要修改上面的代碼但它的思路是相同的 – Eddie
在地圖裏麪點擊偵聽器,簡單地遍歷你的信息框並應用close()方法。 – Eddie