当鼠标移出javascript时,使信息窗口消失

问题描述 投票:-1回答:1

我需要在将光标移动到标记上时显示标记的位置。当我移动标记时,它显示位置。当我离开时,信息窗口不会消失。这令人困惑。我的代码可能有问题。代码是:

    function moveInfoWindow(marker, message) {

        var moveWindow = new google.maps.InfoWindow({
            content: message
        });

        google.maps.event.addListener(marker, 'mouseover', function() {
            moveWindow.open(map, marker);
        });
        google.maps.event.addListener(marker, 'mouseout', function() {
            moveWindow.close();
        });
    }

结果如下:

enter image description here

javascript html
1个回答
0
投票

尝试更改您的代码,如下所示:

google.maps.event.addListener(marker, 'mouseout', (function(infowindow){ 
        return function() {
           infowindow.close();
        };
© www.soinside.com 2019 - 2024. All rights reserved.