当 window.onresize 事件发生时,在 #map_canvas 上设置样式属性:
window.onresize = function(event) {
var style = document.getElementById('map_canvas').style;
style.width = '100%';
style.height = '100%';
style.position = 'absolute';
style.top = '42px';
style.left = '0';
style.right = '0';
style.bottom = '0';
style.z-index = '0';
style.overflow = 'hidden';
google.maps.event.trigger(map, 'resize');
map.setZoom(map.getZoom());
}
考虑到顶部 42px 的 jQuery equiv
window.onresize = function(event) {
var el = $("#map_canvas");
el.css("position", "absolute");
el.css("top", "42px");
el.css("left", "0px");
el.css("right", "0px");
el.css("bottom", "0px");
el.css("width", "100%");
el.css("height", $("body").height() - 42);
el.css("overflow", "hidden");
google.maps.event.trigger(Maps.map, 'resize');
Maps.map.setZoom(Maps.map.getZoom());
}