2011-03-31 174 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}); 
     }); 
    },