为什么 Chrome 中的地图信息窗口中会出现滚动条?

发布于 2024-12-09 18:30:58 字数 1795 浏览 0 评论 0原文

这是 JavaScript:

$(document).ready(function(){

//set location of san antonio 
var san_antonio = new google.maps.LatLng(29.4, -98.544);

//set infowindow
var infoWindow;

//object literal containing the properties
var options = {
  zoom: 9,
  center: san_antonio,
  mapTypeId: google.maps.MapTypeId.ROADMAP 
}

//create the map
var map = new google.maps.Map(document.getElementById('map'), options);

//create marker
var marker = new google.maps.Marker({
  position: san_antonio,
  map:map,
  title: "san antonio"
});


//add 'click' event listener
google.maps.event.addListener(marker, 'click', function(){

//creates infowindow if it already doesn't exist
if (!infoWindow){
  infoWindow = new google.maps.InfoWindow();
}

//create content for infowindow
var content = '<div id="information">'+'<img src="http://a1.twimg.com/profile_images/1549555880/Screenshot.png"/>'+'</div>'

//set content of the infowindow. 
infoWindow.setContent(content);

//open infowindow on click of marker 
infoWindow.open(map,marker);

//ends the event listener
}); 


//ends the DOM loader
});

在 chrome 中,当信息窗口弹出时,我在信息窗口中看到一个不需要的滚动条。如果您查看右下角,您会发现也有一点变形。

在 Chrome 中

my infowindow在 chrome 中渲染

infowindow 在 Firefox 中看起来很棒。昨晚我在台式机上工作时没有遇到这个问题,所以我认为我的 chrome 安装可能在笔记本电脑上损坏了。你怎么认为?这是它在 FireFox 中的样子:

在 FireFox

einfowindow在 firefox 中渲染

我尝试做 div#information{overflow :hidden},但没有任何改变 然后我尝试执行 div#information{overflow:hidden;height:500px;background-color:green;},然后滚动条变得更长。 这告诉我,信息窗口充当其自己的 div,并且“信息”div 的高度导致信息窗口的滚动条变大。 在此处输入图像描述


Here is the JavaScript:

$(document).ready(function(){

//set location of san antonio 
var san_antonio = new google.maps.LatLng(29.4, -98.544);

//set infowindow
var infoWindow;

//object literal containing the properties
var options = {
  zoom: 9,
  center: san_antonio,
  mapTypeId: google.maps.MapTypeId.ROADMAP 
}

//create the map
var map = new google.maps.Map(document.getElementById('map'), options);

//create marker
var marker = new google.maps.Marker({
  position: san_antonio,
  map:map,
  title: "san antonio"
});


//add 'click' event listener
google.maps.event.addListener(marker, 'click', function(){

//creates infowindow if it already doesn't exist
if (!infoWindow){
  infoWindow = new google.maps.InfoWindow();
}

//create content for infowindow
var content = '<div id="information">'+'<img src="http://a1.twimg.com/profile_images/1549555880/Screenshot.png"/>'+'</div>'

//set content of the infowindow. 
infoWindow.setContent(content);

//open infowindow on click of marker 
infoWindow.open(map,marker);

//ends the event listener
}); 


//ends the DOM loader
});

In chrome i get an unwanted scroll bar in the infowindow when it pops up. If you look at the bottom right corner you will notice that there is a little bit of distortion as well.

In Chrome

my infowindow rendering in chrome

The infowindow looks great in Firefox. I was not having this problem last night when I was working on my desktop, so I am thinking that my chrome installation may be broken on my laptop. What do you think? Here is what it looks like in FireFox:

In FireFox

einfowindow rendering in firefox

I tried doing div#information{overflow:hidden}, but nothing changed
I then tried doing div#information{overflow:hidden;height:500px;background-color:green;}, and then the scroll bar just got longer.
This is telling me that the infowindow is acting as its own div and that the 'information' div's height is causing the infowindow's scroll bar to get larger.
enter image description here


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枫以 2024-12-16 18:30:58

尝试添加这个CSS样式:

div#information{
    overflow: hidden;
}

Try adding this css style:

div#information{
    overflow: hidden;
}
南渊 2024-12-16 18:30:58
.gm-style-iw{ overflow: hidden !important;}

这对我有用

.gm-style-iw{ overflow: hidden !important;}

it works for me

我不是你的备胎 2024-12-16 18:30:58

可能是行高的问题。这就是导致我出错的原因。请参阅 Google Maps API v3:InfoWindow 大小调整不正确 回答#11125793(尼克)。

may be an issue with line-height. that's what was causing the error for me. see Google Maps API v3: InfoWindow not sizing correctly answer #11125793 (Nick).

天冷不及心凉 2024-12-16 18:30:58

此解决方案对我有用:

line-height:1.35;
overflow:hidden;
white-space:nowrap;

This solution worked for me:

line-height:1.35;
overflow:hidden;
white-space:nowrap;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文