【问题标题】:Google Maps : open InfoWindow on mouseover, close & reopen on click谷歌地图:鼠标悬停时打开信息窗口,点击时关闭并重新打开
【发布时间】:2012-10-16 14:00:26
【问题描述】:

我在单击时打开了一个带有 InfoWindows 标记的页面。我决定在 MouseOver 上打开正在工作的 InfoWindows。

但我发现必须将鼠标移动到 InfoWindow 的十字处才能关闭它,这对于这些懒惰的互联网访问者来说有点苛刻。所以我在 Marker 的 Click 上添加了一个 Close 事件,该事件也有效。

我想不出的工作是能够重新打开标记单击上的信息窗口,而不是必须鼠标悬停才能重新将鼠标悬停在标记上。

我的代码:

google.maps.event.addListener(CalMarker, 'mouseover', function() {
    infowindow.setContent(contentStringCal);
    infowindow.open(map,CalMarker);
});
google.maps.event.addListener(CalMarker, 'click', function() {
    infowindow.close(map,CalMarker);
});

任何人都可以通过单击标记帮助我重新打开窗口吗?

提前致谢

PS:不能在帖子开头说“嗨”,这很奇怪。

【问题讨论】:

    标签: google-maps google-maps-api-3 mouseover infowindow


    【解决方案1】:

    试试这个:

    google.maps.event.addListener(CalMarker, 'mouseover', function() {
        //open the infowindow when it's not open yet
        if(contentStringCal!=infowindow.getContent())
        {
          infowindow.setContent(contentStringCal);
          infowindow.open(map,CalMarker);
        }
    });
    
    google.maps.event.addListener(CalMarker, 'click', function() {
        //when the infowindow is open, close it an clear the contents
        if(contentStringCal==infowindow.getContent())
        {
          infowindow.close(map,CalMarker);
          infowindow.setContent('');
        }
        //otherwise trigger mouseover to open the infowindow
        else
        {
          google.maps.event.trigger(CalMarker, 'mouseover');
        }
    });
    
    //clear the contents of the infwindow on closeclick
    google.maps.event.addListener(infowindow, 'closeclick', function() {
          infowindow.setContent('');
    });
    

    演示:http://jsfiddle.net/doktormolle/JXqLa/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      相关资源
      最近更新 更多