最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is a scroll bar coming out in my maps infowindow in chrome? - Stack Overflow

programmeradmin6浏览0评论

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=".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

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

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.


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./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

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

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.


Share Improve this question edited Oct 14, 2011 at 15:51 Spencer Cooley asked Oct 14, 2011 at 15:17 Spencer CooleySpencer Cooley 8,85116 gold badges50 silver badges64 bronze badges 1
  • Very similar question here: stackoverflow./questions/1554893/… – Simon E. Commented Aug 15, 2014 at 1:09
Add a ment  | 

4 Answers 4

Reset to default 5

Try adding this css style:

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

it works for me

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).

This solution worked for me:

line-height:1.35;
overflow:hidden;
white-space:nowrap;
发布评论

评论列表(0)

  1. 暂无评论