Google Maps and jQuery Tabs

后端 未结 8 2399
温柔的废话
温柔的废话 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

    If you are still struggling to get this right like I was, Try this.

     var hasLoadedMap = false;
    $( "#tabs" ).tabs({
          activate: function( event, ui ) {
              //console.log(ui.newTab.context.id);
                if(!hasLoadedMap && ui.newTab.context.id == 'ui-id-4') { //my map tab has index 4. This will avoid initialization for other tabs
                    console.log(ui.newTab.context.id);
                    initialize();    //google map initialization code
                    hasLoadedMap = true;
              }
    
          }
    });  
    

    I have adapted the other answers above into something more current.

提交回复
热议问题