【问题标题】:Resize Google map on mouseover鼠标悬停时调整谷歌地图大小
【发布时间】:2011-10-25 18:30:08
【问题描述】:

我希望在用户将鼠标悬停在地图的小版本上时调整 Google 地图的大小。问题是当我将鼠标悬停在地图导航元素时也会触发 mouseout 事件:

JS:

google.maps.event.addListener(map, 'mouseover', function() {
        $('#map_canvas').addClass('over',200);
});
google.maps.event.addListener(map, 'mouseout', function() {
        $('#map_canvas').removeClass('over',200);
});

HTML 元素只是一个简单的<div>

<div id="map_canvas"></div>

over 类只是为更大的视图添加了一些样式。它使用 jQuery UI 动画类更改来制作动画。

【问题讨论】:

    标签: jquery jquery-ui google-maps-api-3


    【解决方案1】:

    您是否尝试过将 mouseenter 和 mouseleave 绑定到地图的包含 div 并这样做而不是 mouseout/mouseover 作为地图对象上的事件侦听器?

    $('#map').mouseenter(function() { 
    /* add class */
     }).mouseleave(function() {
     /*remove class */ 
    });
    

    【讨论】:

    • 是的,但是在 Google 地图加载到画布/div 之后,该事件不会被触发
    • 啊,是的,因为它是在 DOM 内容加载后添加的,对吧?你试过$('#map').live('mouseenter', function() { /* add.. */ }).live('mouseleave', function() { ... });吗? live 允许您将事件绑定到文档准备好后创建和/或修改的元素。我想它应该可以工作,但我还没有亲身测试过。 mouseout 可能不起作用的原因是mouseout fires when the pointer moves out of the child element as well (ie onto nav controls), while mouseleave fires only when the pointer moves out of the bound element. (jquery.com)
    • 这也会产生弹跳效果……Google JS 会以某种方式干扰 jQuery。我现在通过在效果上使用延迟计时器来修复它。
    猜你喜欢
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多