0

我正在尝试将鼠标悬停事件侦听器添加到 Google 地图覆盖视图。我一直在关注这个问题,但无法让听众工作。这是我的代码:

InfoWindow.prototype = new google.maps.OverlayView;
InfoWindow.prototype.onAdd = function() {
  this.getPanes().overlayMouseTarget.appendChild(this.$content.get(0));
  this.getPanes().overlayMouseTarget.parentNode.style.zIndex = 100000;
  google.maps.event.addListener(this, 'mouseover', function() {
    console.log('MOUSEOVER');
  });
};

这不会给出任何错误,但也不会在鼠标悬停时做任何事情。我也尝试过使用this.listeners

this.listeners = [
    google.maps.event.addDomListener(this, "mouseover", function (e) {
       console.log('MOUSEOVER');
    })
];

但这也无济于事。我究竟做错了什么?

4

1 回答 1

0

For the domListener to work, you need to attach it to a dom node:

google.maps.event.addDomListener(this.$content.get(0), "mouseover", function (e) { console.log('MOUSEOVER'); });

于 2013-05-29T14:17:52.747 回答