简体   繁体   English

将jscrollpane添加到Google地图信息窗口

[英]adding jscrollpane to a google maps infowindow

so it's basically all in the title... I'm using jscrollpane elsewhere on the page so I know it works, but I can't get anything besides the default scrollbars on the google maps infowindow. 所以基本上是标题中的所有内容...我在页面上的其他地方使用了jscrollpane,所以我知道它可以工作,但是除了Google Maps Infowindow上的默认滚动条之外,我什么也没得到。 some code: 一些代码:

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

Seems like the problem is maybe a) jscrollpane is initialized before the infowindow is created, b) I'm targeting a child element of the infowindow when I need to target something higher up, or c) the gmaps API is just not playing nice with jscrollpane and there's nothing I can do. 似乎是问题所在,可能是a)在创建信息窗口之前初始化了jscrollpane,b)当我需要定位更高级别的东西时,我将信息窗口的子元素作为目标,或者c)gmaps API不能很好地与jscrollpane,我无能为力。 But I really have no idea. 但是我真的不知道。

Aha! 啊哈! The code below works: 以下代码有效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM