2011-03-31 105 views
0

所以它基本上都是在標題中......我在頁面上的其他地方使用jscrollpane,所以我知道它的工作原理,但除了谷歌地圖上的默認滾動條之外我什麼也得不到信息窗口。一些代碼:將jscrollpane添加到谷歌地圖infowindow

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 
    }, 

好像問題是也許)JScrollPane的是在創建信息窗口之前進行初始化,B)我針對信息窗口的子元素,當我需要的東西的目標上漲,或c )gmaps API對jscrollpane沒什麼好處,我也沒有辦法。但我真的不知道。

回答

0

啊哈!下面的代碼工作:

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}); 
     }); 
    },