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

javascript - Why Google Map infowindow has a scrollbar - Stack Overflow

programmeradmin2浏览0评论

I have a google map in my website and for some reason when the page initially load there is a scroll bar for the info window but after clicking on other marker and ing back to the initially marker that was showing the info window, there is no scroll bar.

Here is a screenshot when the page loads:

After I click on the other markers with the "H" icon and e back to the building icon, the scroll bar is gone:

Here is my HTML/CSS/JQuery code:

<!DOCTYPE html>

<html>

<head>
<title>Map Location</title>
<script type="text/javascript" src=".11.0.min.js"></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var infowindow = null;
var firstOne = null;
$(document).ready(function () {
        initialize();
});

function initialize() {
    var centerMap = new google.maps.LatLng(41.04356, -73.784445);
    var myOptions = {
        zoom: 12,
        center: centerMap,
        scaleControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    setMarkers(map, sites);
    infowindow = new google.maps.InfoWindow({
        content: "loading...", maxWidth: 350
    });
    infowindow.setContent(firstOne.html);
    infowindow.open(map, firstOne);
    //var bikeLayer = new google.maps.BicyclingLayer();
    //bikeLayer.setMap(map);
}

var sites = [
    ['Administrative Office', 41.0237, -73.701239, 1, '<span class=ttl><b> Administrative Office</b></span><br><br><span class=sbj>0 Westchester Avenue<br>Purchase, NY 10577<br><img src="theImages/phone.png" width="12" height="12" /> 914.963.0700</span>'],
    ['Purchase Office', 41.005615, -73.69566551, 2, '<span class=ttl><b>Purchase Office</b></span><br><br><span class=sbj>3 Westchester Avenue<br>Purchase, NY 10577<br><img src="theImages/phone.png" width="12" height="12" /> 914.533.4570</span>'],
    ['Rye Office', 40.9756737, -73.65614, 3, '<span class=ttl><b>Rye Office</b></span><br><br><span class=sbj>45 Road<br>Rye, NY 10580<br><img src="theImages/phone.png" width="12" height="12" /> 914.845.8822</span>'],
    ['Scarsdale Office', 40.973478, -73.8433, 4, '<span class=ttl><b>Scarsdale Office</b></span><br><br><span class=sbj>6 White Plains Road, Suite 270<br>Scarsdale, NY 10583<br><img src="theImages/phone.png" width="12" height="12" /> 914.213.7670</span>'],
    ['White Plains Office', 41.04579, -73.7464, 5, '<span class=ttl><b>White Plains Office</b></span><br><br><span class=sbj>5 Westchester Avenue (GPS Enter: West Harrison)<br>White Plains, NY 10604<br><img src="theImages/phone.png" width="12" height="12" /> 914.672.0776</span>'],
    ['White Plains Office', 41.0563, -73.75618, 6, '<span class=ttl><b>White Plains Office</b></span><br><br><span class=sbj>5 Davfgs Avenue<br>White Plains, NY 10605<br><img src="theImages/phone.png" width="12" height="12" /> 914.541.2450</span>'],
    ['Yonkers Office', 40.9442, -73.8554, 6, '<span class=ttl><b>Yonkers Office</b></span><br><br><span class=sbj>5 Hill Blvd<br>Yonkers, NY 10710<br><img src="theImages/phone.png" width="12" height="12" /> 914.545.8022</span>']
];


function setMarkers(map, markers) {
    for (var i = 0; i < markers.length; i++) {
        var sites = markers[i];
        var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
        var marker = new google.maps.Marker({
            position: siteLatLng,
            map: map,
            title: sites[0],
            zIndex: sites[3],
            html: sites[4]
        });
        var contentString = "Some content";
        google.maps.event.addListener(marker, "click", function () {
            //alert(this.html);
            infowindow.setContent(this.html);
            infowindow.open(map, this);
        });
        if(!firstOne) {
            firstOne = marker;
            marker.setIcon('theImages/hq.png');
        }
        else {
            marker.setIcon('theImages/hicon.png');
        }
    }           
}
</script>
<style>
.ttl {
    font-family: Arial, Verdana;
    font-size: 15px;
    color: #049600;
    text-align: left;
}
.sbj {
    font-family: Tahoma, Arial, Verdana;
    font-size: 12px;
    font-weight: bold;
    text-align: left;
}
</style>
</head>

<body>
<div id="map_canvas" style="width: 1050px; height: 395px; line-height: normal ! important"></div>
</body>
</html>

When the page loads, there is no scroll bar. Once the page fully loads, the scroll bar shows up. How do I fix the scroll bar issue?

I have a google map in my website and for some reason when the page initially load there is a scroll bar for the info window but after clicking on other marker and ing back to the initially marker that was showing the info window, there is no scroll bar.

Here is a screenshot when the page loads:

After I click on the other markers with the "H" icon and e back to the building icon, the scroll bar is gone:

Here is my HTML/CSS/JQuery code:

<!DOCTYPE html>

<html>

<head>
<title>Map Location</title>
<script type="text/javascript" src="http://code.jquery./jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://maps.google./maps/api/js?sensor=false"></script>
<script type="text/javascript">
var infowindow = null;
var firstOne = null;
$(document).ready(function () {
        initialize();
});

function initialize() {
    var centerMap = new google.maps.LatLng(41.04356, -73.784445);
    var myOptions = {
        zoom: 12,
        center: centerMap,
        scaleControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    setMarkers(map, sites);
    infowindow = new google.maps.InfoWindow({
        content: "loading...", maxWidth: 350
    });
    infowindow.setContent(firstOne.html);
    infowindow.open(map, firstOne);
    //var bikeLayer = new google.maps.BicyclingLayer();
    //bikeLayer.setMap(map);
}

var sites = [
    ['Administrative Office', 41.0237, -73.701239, 1, '<span class=ttl><b> Administrative Office</b></span><br><br><span class=sbj>0 Westchester Avenue<br>Purchase, NY 10577<br><img src="theImages/phone.png" width="12" height="12" /> 914.963.0700</span>'],
    ['Purchase Office', 41.005615, -73.69566551, 2, '<span class=ttl><b>Purchase Office</b></span><br><br><span class=sbj>3 Westchester Avenue<br>Purchase, NY 10577<br><img src="theImages/phone.png" width="12" height="12" /> 914.533.4570</span>'],
    ['Rye Office', 40.9756737, -73.65614, 3, '<span class=ttl><b>Rye Office</b></span><br><br><span class=sbj>45 Road<br>Rye, NY 10580<br><img src="theImages/phone.png" width="12" height="12" /> 914.845.8822</span>'],
    ['Scarsdale Office', 40.973478, -73.8433, 4, '<span class=ttl><b>Scarsdale Office</b></span><br><br><span class=sbj>6 White Plains Road, Suite 270<br>Scarsdale, NY 10583<br><img src="theImages/phone.png" width="12" height="12" /> 914.213.7670</span>'],
    ['White Plains Office', 41.04579, -73.7464, 5, '<span class=ttl><b>White Plains Office</b></span><br><br><span class=sbj>5 Westchester Avenue (GPS Enter: West Harrison)<br>White Plains, NY 10604<br><img src="theImages/phone.png" width="12" height="12" /> 914.672.0776</span>'],
    ['White Plains Office', 41.0563, -73.75618, 6, '<span class=ttl><b>White Plains Office</b></span><br><br><span class=sbj>5 Davfgs Avenue<br>White Plains, NY 10605<br><img src="theImages/phone.png" width="12" height="12" /> 914.541.2450</span>'],
    ['Yonkers Office', 40.9442, -73.8554, 6, '<span class=ttl><b>Yonkers Office</b></span><br><br><span class=sbj>5 Hill Blvd<br>Yonkers, NY 10710<br><img src="theImages/phone.png" width="12" height="12" /> 914.545.8022</span>']
];


function setMarkers(map, markers) {
    for (var i = 0; i < markers.length; i++) {
        var sites = markers[i];
        var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
        var marker = new google.maps.Marker({
            position: siteLatLng,
            map: map,
            title: sites[0],
            zIndex: sites[3],
            html: sites[4]
        });
        var contentString = "Some content";
        google.maps.event.addListener(marker, "click", function () {
            //alert(this.html);
            infowindow.setContent(this.html);
            infowindow.open(map, this);
        });
        if(!firstOne) {
            firstOne = marker;
            marker.setIcon('theImages/hq.png');
        }
        else {
            marker.setIcon('theImages/hicon.png');
        }
    }           
}
</script>
<style>
.ttl {
    font-family: Arial, Verdana;
    font-size: 15px;
    color: #049600;
    text-align: left;
}
.sbj {
    font-family: Tahoma, Arial, Verdana;
    font-size: 12px;
    font-weight: bold;
    text-align: left;
}
</style>
</head>

<body>
<div id="map_canvas" style="width: 1050px; height: 395px; line-height: normal ! important"></div>
</body>
</html>

When the page loads, there is no scroll bar. Once the page fully loads, the scroll bar shows up. How do I fix the scroll bar issue?

Share Improve this question asked Mar 14, 2014 at 15:21 Si8Si8 9,23522 gold badges119 silver badges223 bronze badges 1
  • Very similar question here: stackoverflow./questions/1554893/… – Simon E. Commented Aug 15, 2014 at 1:05
Add a ment  | 

2 Answers 2

Reset to default 3

try this:

#map_canvas > div > div:nth-child(1) > div > div:nth-child(3) > div:nth-child(3) > div > div.gm-style-iw {
    overflow: visible !important;
}

Since it looks like you're headed down the route of including a lot of information in your info windows, you might benefit more from pursuing the route of building your own custom info windows. They have a great example up at http://gmaps-samples-v3.googlecode./svn/trunk/infowindow_custom/infowindow-custom.html . I noticed you have jquery on your page as well, you might even benefit from looking at this post on how to integrate jQuery UI using Google's "InfoBox" extension - http://thewebstorebyg.wordpress./2012/10/24/google-maps-api-v3-tabs-inside-the-infowindow-using-infobox/

发布评论

评论列表(0)

  1. 暂无评论