Google Maps and jQuery Tabs

后端 未结 8 2390
温柔的废话
温柔的废话 2020-12-01 15:29

I have slight problem with Google maps included in simple jQuery Tabs.

Below I pasted the code:

jQuery:

$(document).ready(function() {

             


        
8条回答
  •  醉梦人生
    2020-12-01 15:44

    I went with a different approach - initialize the map after the tab is activated. Here's my code:

    //Default Action
    jQuery(".tab_content").hide(); //Hide all content
    jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
    jQuery(".tab_content:first").show(); //Show first tab content
    
    //On Click Event
    jQuery("ul.tabs li").click(function() {
        jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
        jQuery(this).addClass("active"); //Add "active" class to selected tab
        jQuery(".tab_content").hide(); //Hide all tab content
        var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        jQuery(activeTab).fadeIn(); //Fade in the active content
        if(activeTab == '#location_tab') {      
            initialize();
        }
        return false;
    });
    

    Make sure that the tab with your map's ID matches with the script's. In my case its "location_tab".

提交回复
热议问题