Javascript 关注谷歌地图';标记鼠标上方的s信息窗口
我想把信息窗口的焦点放在鼠标悬停在标记上。只要他停留在信息窗口,窗口就会打开。下面是我的代码Javascript 关注谷歌地图';标记鼠标上方的s信息窗口,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,我想把信息窗口的焦点放在鼠标悬停在标记上。只要他停留在信息窗口,窗口就会打开。下面是我的代码 content="<div class='info_content' id='info"+obj.customer_id+"'><span>"+j+".</span><h1><a href='<?php echo Mage::getUrl() ?>"+obj.identifier+"<?php echo $suffix; ?>
content="<div class='info_content' id='info"+obj.customer_id+"'><span>"+j+".</span><h1><a href='<?php echo Mage::getUrl() ?>"+obj.identifier+"<?php echo $suffix; ?>'>"+obj.company.substr(0, 28)+"</a> </h1><br /><p>"+address+"</p><p>"+Math.round(obj.distance)+" Km Away</p><br /><button type='button' value='Get Direction' class='button_input' onclick='closeInfoWindow(),calcRoute("+obj.latitude+","+obj.longitude+")' name='Get Direction'>Get Direction</button></div>";
marker = new google.maps.Marker({
position: position,
map: map,
title: obj.company,
icon:icon,
});
if(i==0)
{
map.setCenter(marker.getPosition())
}
google.maps.event.addListener(marker,'mouseover', (function(marker,content,infowindow){
return function() {
infowindow.close();
infowindow.setContent(content);
infowindow.open(map,marker);
jQuery("#info"+obj.customer_id).focus();
};
})(marker,content,infowindow));
google.maps.event.addListener(marker,'mouseout', (function(marker,content,infowindow){
return function() {
};
})(marker,content,infowindow));
content=“+j+”
“+address+”“+Math.round(obj.distance)+“Km远”
获取方向”;
marker=新的google.maps.marker({
职位:职位,,
地图:地图,
标题:obj公司,
图标:图标,
});
如果(i==0)
{
map.setCenter(marker.getPosition())
}
google.maps.event.addListener(marker,'mouseover',(函数(marker,content,infowindow){
返回函数(){
infowindow.close();
infowindow.setContent(content);
信息窗口。打开(地图、标记);
jQuery(“#info”+obj.customer_id).focus();
};
})(标记、内容、信息窗口);
google.maps.event.addListener(marker,'mouseout',(函数(marker,content,infowindow){
返回函数(){
};
})(标记、内容、信息窗口);
除非设置了tabindex
属性(如果我没有错,可以使用此属性聚焦任何元素),否则无法聚焦div元素。焦点动作通常用于表单/文本元素
我举了一个有效的例子(见):
window.onload=function(){
var map=new google.maps.map(document.getElementById('map'),{
中心:新google.maps.LatLng(22.669,77.709),
缩放:5,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var content=“你好世界”;
var infowindow=new google.maps.infowindow();
var marker=new google.maps.marker({
位置:新google.maps.LatLng(22.669,77.709),
地图:地图
});
google.maps.event.addListener(标记'mouseover',函数(){
infowindow.setContent(content);
信息窗口。打开(地图、标记);
});
google.maps.event.addListener(标记'mouseout',函数(){
//
});
google.maps.event.addListener(infowindow,'domready',function(){
$('info01').focus();
});
};
在鼠标悬停返回函数中,jQuery(“#info”+obj.customer\u id)
为空吗?是的,我尝试过,但没有成功。请检查我在答案中发布的答案。你有一个有效的例子。它与您的代码非常相似,只是我将一些html删除到了content
变量中,因为示例中不需要它。无论如何,我很确定您可以将此代码集成到您的代码中。此外,关于可聚焦的内容,请参阅
window.onload = function(){
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(22.669, 77.709),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var content="<div class='info_content' id='info01' tabindex='1'>hello world</div>";
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
position: new google.maps.LatLng(22.669, 77.709),
map: map
});
google.maps.event.addListener(marker, 'mouseover', function(){
infowindow.setContent(content);
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function(){
//
});
google.maps.event.addListener(infowindow, 'domready', function(){
$('#info01').focus();
});
};