谷歌地图在标记上弹跳动画的时间有限

cgv*_*val 4 html javascript html5 google-maps google-maps-api-3

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

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

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

Uncaught TypeError: Cannot call method 'setAnimation' of undefined
        (anonymous function)
Run Code Online (Sandbox Code Playgroud)

任何想法可能是什么?

Sco*_*ttE 12

这工作正常(使用单个全局标记对象)

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

    setTimeout(function() {
        marker.setAnimation(null)
    }, 3000);
Run Code Online (Sandbox Code Playgroud)

我的猜测是你正在进行交流,而你的setTimeout我不在范围内.试试这个:

    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);
}
Run Code Online (Sandbox Code Playgroud)

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

Javascript如何在迭代列表操作中使用setTimeout?