【问题标题】:Google Maps Bounce Animation on Marker for a limited period谷歌地图在限定时间内在标记上弹跳动画
【发布时间】:2013-01-17 10:38:01
【问题描述】:

我希望标记弹跳几秒钟并最终自动停止。我正在尝试这段代码:

1. globalMarkers[i].setAnimation(google.maps.Animation.BOUNCE);
2. setTimeout(function() {
3.    globalMarkers[i].setAnimation(null)
4. }, 3000);

但由于某种原因,第 1 行执行(因此标记将开始弹跳)但第 3 行返回以下错误:

Uncaught TypeError: Cannot call method 'setAnimation' of undefined
        (anonymous function)

有什么想法吗?

【问题讨论】:

  • 你能再贴一些代码吗?

标签: javascript html google-maps google-maps-api-3


【解决方案1】:

这很好用(使用单个全局标记对象)

    marker.setAnimation(google.maps.Animation.BOUNCE);

    setTimeout(function() {
        marker.setAnimation(null)
    }, 3000);

我的猜测是您正在交互,而您的 setTimeout i 不在范围内。试试这个:

    for (var x = 0; x < 5; x++) {
        var marker = markers[x];
        marker.setAnimation(google.maps.Animation.BOUNCE);
        stopAnimation(marker);
    }


function stopAnimation(marker) {
    setTimeout(function () {
        marker.setAnimation(null);
    }, 3000);
}

这里有一些更有创意的解决方案:

Javascript how to use setTimeout on an iterative list operation?

【讨论】:

    猜你喜欢
    • 2013-01-31
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2014-02-20
    • 2018-01-19
    • 1970-01-01
    相关资源
    最近更新 更多