Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 悬停Google地图时禁用鼠标事件侦听器_Javascript_Google Maps_Mouseevent_Addeventlistener_Event Listener - Fatal编程技术网

Javascript 悬停Google地图时禁用鼠标事件侦听器

Javascript 悬停Google地图时禁用鼠标事件侦听器,javascript,google-maps,mouseevent,addeventlistener,event-listener,Javascript,Google Maps,Mouseevent,Addeventlistener,Event Listener,我添加了2个EventListener,以控制滚动,并使其在Chrome上流畅流畅(尤其是),默认情况下,Chrome具有可怕的行为 if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false); window.onmousewheel = document.onmousewheel = wheel; var time = 1300; var distance = 270; funct

我添加了2个EventListener,以控制滚动,并使其在Chrome上流畅流畅(尤其是),默认情况下,Chrome具有可怕的行为

if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

var time = 1300;
var distance = 270;

function wheel(event) {
    if (event.wheelDelta) delta = event.wheelDelta / 120;
    else if (event.detail) delta = -event.detail / 3;

    handle();
    if (event.preventDefault) event.preventDefault();
    event.returnValue = false;
}

function handle() {

    $('html, body').stop().animate({
        scrollTop: $(window).scrollTop() - (distance * delta)
    }, time);
}


$(document).keydown(function (e) {

    switch (e.which) {
        //up
        case 38:
            $('html, body').stop().animate({
                scrollTop: $(window).scrollTop() - distance
            }, time);
            break;

            //down
        case 40:
            $('html, body').stop().animate({
                scrollTop: $(window).scrollTop() + distance
            }, time);
            break;
    }
});
除了我需要添加一个GoogleMapsAPIv3地图之外,一切都很好。它还有另一个EventListener,当鼠标悬停在地图上并且您使用鼠标滚轮时,它会放大和缩小。当鼠标悬停在地图上时,如何禁用脚本?这是我的页面链接(你可以看到行为),live:

(我不确定我是否正确理解了这个问题)

对我来说,鼠标悬停在地图上时,你的脚本根本不起作用。当我在地图上使用鼠标滚轮时,地图将被缩放,但页面不会滚动(我想这是理想的行为)

只有当前正在运行的动画队列会在您浏览地图时滚动页面。当这是您想要避免的情况时,请观察贴图的
鼠标悬停
-事件并停止动画:

  google.maps.event.addListener(map,'mouseover',function(e){
    $('html, body').stop();
  });
要防止页面在Firefox中滚动,请添加以下内容:

  google.maps.event.addDomListener(map.getDiv(),'DOMMouseScroll',function(e){
    e.stopPropagation();
  });

它应该可以防止事件冒泡到文档中。

将其放在div:
style=“用户选择:无;指针事件:无;”

将映射的
滚轮属性设置为
false
,但我想使用它。难道就不能在悬停地图时禁用“我的”脚本吗?对不起,我误读了这个问题,这正是我面临的问题(至少在Firefox中)。当我将地图悬停并使用鼠标滚轮时,地图的缩放被激活,页面滚动。我将很快尝试这段代码:)它真的很奇怪!我试过使用Internet Explorer,但没有成功。而在Firefox上,它确实做到了。。尝试访问问题处的链接…:(我用第二个代码片段更新了页面(),但是Firefox仍然是一个蠢货。:P编辑:我在G Maps函数中添加了这些代码片段,因为如果我将它们添加到google.Maps.event.addDomListener(窗口,'load',initialize')的正上方,则不会再加载地图了。请在创建
google.Maps.map
的语句之后添加代码片段。