Google Maps Not Working in jQuery Tabs

前端 未结 13 1719
滥情空心
滥情空心 2020-12-09 22:56

Google maps not working when placed inside jQuery tabs is a question that\'s all over the web. In my research so far none of the solutions seem to work. Hopefully someone he

相关标签:
13条回答
  • 2020-12-09 23:24

    Give this a try:

    Change

    <li><a href="#">Map Tab</a></li> 
    

    to

    <li><a href="#" id="maptab">Map Tab</a></li>
    

    Then add this javascript

    $(document).ready(function(){
      $('#maptab').bind('onClick', function() {
        google.maps.event.trigger(map, 'resize');
      });
    });
    

    In a script tag at the top of the page. What this should do for you:

    By adding the id attribute to the tab link, you're explicitly specifying there's a map in there. You're then listening for the onClick event provided by the jQuery tabs library that fires when a tab is selected, which triggers re-sizing the map.

    0 讨论(0)
提交回复
热议问题