Google Maps API v3, jQuery UI Tabs, map not resizing

后端 未结 5 1797
闹比i
闹比i 2020-12-10 09:34

I am using Google Maps API v3, being displayed on a jQuery UI Tab. I have been struggling with triggering my google map to resize correctly when the tab displaying the map

5条回答
  •  攒了一身酷
    2020-12-10 10:26

    Add the following to your tabs constructor:

    $(function() {
        $("#myTabs").tabs({
            show: function(e, ui) {
                if (ui.index == 0) {
                    google.maps.event.trigger(myMap, "resize");
                }
            }
        });
    });
    

    You should test ui.index for the 0-based index of the panel that contains your Google map, and of course update references to myMap and #myTabs.

    See the Events section of the Map object documentation for more information about dispatching a resize event trigger.

提交回复
热议问题