好的,我花了很多时间来找到解决方案。但我现在开始工作了!
问题出在 InfoBubble 代码中。所有事件都被阻止在地图上冒泡,显然是为了防止 Ghostclicks 通过气泡。不幸的是,这也阻止了所有其他侦听器正常工作。处理事件的代码片段位于第 808 行:
/**
* Add events to stop propagation
* @private
*/
InfoBubble.prototype.addEvents_ = function() {
// We want to cancel all the events so they do not go to the map
var events = ['mousedown', 'mousemove', 'mouseover', 'mouseout', 'mouseup',
'mousewheel', 'DOMMouseScroll', 'touchstart', 'touchend', 'touchmove',
'dblclick', 'contextmenu', 'click'];
var bubble = this.bubble_;
this.listeners_ = [];
for (var i = 0, event; event = events[i]; i++) {
this.listeners_.push(
google.maps.event.addDomListener(bubble, event, function(e) {
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
})
);
}
};
现在您可以从阵列中删除您想要使用而不会产生太大影响的事件。我决定采取一种更温和的方法,只允许那些我真正需要让我的滑块(和链接)工作的事件:
InfoBubble.prototype.addEvents_ = function() {
// bla bla code, see above
google.maps.event.addDomListener(bubble, event, function(e) {
// allow all mouseup-events
if(e.type == 'mouseup') { return; }
// allow click events from my button classes
if(e.type == 'click' && $(e.fromElement).closest('.btn') ) { return; }
// allow events that come from my jquery ui slider
if( $(e.fromElement).is("div[class^='ui-slider-'],div[class*=' ui-slider-']") ) { return; }
// else: do what you have to do
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
);
// bla bla code, see above
};
您可以在此处找到一个工作示例:FIDDLE