小编stu*_*hoi的帖子

Google Chrome 84 + Google Maps InfoWindow:点击关闭按钮时防止网页跳转

在使用 JavaScript API 关闭嵌入在网页中的 Google 地图中的 InfoWindow 时,Google Chrome v84 中似乎有一个奇怪的行为:

每当页面没有滚动到顶部时,单击 InfoWindow 上的关闭按钮会使页面的滚动位置15px向下跳转。

这在版本 83 及更低版本中没有发生。

这是一个简单的可重现示例。向下滚动页面直到地图位于视口中,单击标记,关闭信息窗口,页面将向下滚动15px

function initialize() {

  const mapOptions = {
    zoom: 5,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: new google.maps.LatLng(0, 0)
  };

  const map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  const marker = new google.maps.Marker({
    position: new google.maps.LatLng(0, 0),
    map: map,
    title: 'Nothing here'
  });

  const infowindow = new google.maps.InfoWindow({
    content: 'Hello World'
  });

  google.maps.event.addListener(marker, 'click', function() …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps google-chrome google-maps-api-3

7
推荐指数
1
解决办法
817
查看次数