I am using the Google Maps API to pull back a map with a series of points on it. I am also pulling back directions which are displayed in the element with ID=”directionsPanel”. This is all well and good except for the fact that when we get past a certain number of points (3 in Firefox, 4 in Chrome) they spill off the page.
I am using the following jQuery code to detect what the element height is (presumably after the directions are loaded) and then adjust it accordingly:
$(document).ready(function() {
if($.browser.mozilla)
{
var sHeight = $("#directionsPanel").height();
sHeight = (sHeight * 1.5);
$("#directionsPanel").height(sHeight);
}
else
{
// do stuff for other browsers
}
});
Unfortunately the element is not being adjusted to the right amount (perhaps it is not detecting the correct initial height?) and things are still spilling off the page. Any thoughts on how I might make this more robust?
Google Maps API probably lets you specify a callback function for when the map has loaded, and that is where you should put your code.
For example:
Don’t use
$(document).ready()since that executes immediately when the DOM is loaded.