2011-03-31 5 views
0

donc il est essentiellement tout dans le titre ... J'utilise jscrollpane ailleurs sur la page afin que je sais que cela fonctionne, mais je ne peux rien obtenir en plus des scrollbars par défaut sur les cartes google infowindow. un code:ajouter jscrollpane à un infowindow google maps

PanelList = function(speed, target) { // jscrollpane is working on 
    this.speed = speed || 300;   // these panels next to the google map 
    this.target = target || '#panel-target'; 
    this.array = []; 
    $('.scrollpane').jScrollPane({autoReinitialise: true}); 
    this.scrollAPI = $(this.target).data('jsp'); 
} 

// ... lots of code left out for brevity 

MarkerList = function(map) { 
    this.map = map; 
    this.array = []; 
    this.infoWindow = new google.maps.InfoWindow(); 
    this.savedBounds = new google.maps.LatLngBounds(); 
    var cachedThis = this; 
    google.maps.event.addListener(map, 'click', function() { 
     cachedThis.infoWindow.close(); 
    }); 
} 

MarkerList.prototype = { 
    makeInfoWindow: function(map, marker) { 
     this.infoWindow.setContent('<div class="infowindow scrollpane">' 
            +'<h2>'+marker.title+'</h2>' 
            +marker.content 
            +'</div>'); 
     this.infoWindow.open(map, marker); 
     // assume I should add some jscrollpane code here 
     // but nothing seems to work 
    }, 

On dirait que le problème est peut-être) JScrollPane est initialisé avant la infowindow est créé, b) je cible un élément enfant du infowindow quand je dois cibler quelque chose plus haut, ou c) L'API gmaps ne fonctionne pas bien avec jscrollpane et je ne peux rien faire. Mais je n'en ai vraiment aucune idée.

Répondre

0

Aha! Le code ci-dessous fonctionne:

makeInfoWindow: function(map, marker) { 
     this.infoWindow.setContent('<div class="infowindow">' 
            +'<h2>'+marker.title+'</h2>' 
            +marker.content 
            +'</div>'); 
     this.infoWindow.open(map, marker); 
     google.maps.event.addListener(this.infoWindow, 'domready', function() { 
      $('.infowindow').parent().parent().jScrollPane({autoReinitialise: true}); 
     }); 
    },