前使用谷歌地圖V2,我能夠從去地圖和處理,並取消鼠標滾動事件縮放地圖停止滾動鼠標(DOMMouseScroll)事件。但是,在v3中,這不再有效。GMaps V3:如何取消鼠標滾動的事件,他們滾動地圖
Here is an example. Try to scroll through the text with the mouse wheel
注意如何拖動,他們得到的地圖之前雙擊被取消,但是如果你試圖通過文字滾動,那麼DOMMouseScroll事件去一直到地圖。
取消事件的代碼基本相同,V2,看起來像這樣:
// Set the overlay's div_ property to this DIV
this.div_ = div;
var cancelEvent = function(e)
{
if((navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) ||
navigator.userAgent.indexOf('Opera') > -1) {
window.event.cancelBubble = true;
window.event.returnValue = false;
} else {
e.stopPropagation();
}
return false;
}
var panes = this.getPanes();
panes.floatPane.appendChild(div);
var stealEvents = [ 'mousedown', 'dblclick', 'DOMMouseScroll', 'onmousewheel', 'drag'];
for(i=0; i < stealEvents.length; i++){
google.maps.event.addDomListener(this.div_, stealEvents[i], cancelEvent);
}
// for IE/Opera
if((navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) ||
navigator.userAgent.indexOf('Opera') > -1) {
this.div_.attachEvent('onmousewheel', cancelEvents);
}
// for safari
if (navigator.userAgent.indexOf('AppleWebKit/') > -1) {
this.div_.onmousewheel = cancelEvents;
}
好吧。我是想只取消該事件,但關閉地圖縮放/移動在必要時也可以。我想你不能在第二版中取消那個事件。 – 2013-05-01 16:59:12