最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps Bounce Animation on Marker for a limited period - Stack Overflow

programmeradmin2浏览0评论

I wish that a marker bounces for a few seconds and eventually stops automatically.. I am trying this code :

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

but for some reason, line 1 executes (hence marker will start bouncing) but the 3rd line returns the following error:

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

Any ideas what it could be?

I wish that a marker bounces for a few seconds and eventually stops automatically.. I am trying this code :

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

but for some reason, line 1 executes (hence marker will start bouncing) but the 3rd line returns the following error:

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

Any ideas what it could be?

Share Improve this question asked Feb 2, 2013 at 1:45 cgvalcgval 1,0965 gold badges14 silver badges31 bronze badges 1
  • could you post some more code? – ScottE Commented Feb 2, 2013 at 2:04
Add a ment  | 

1 Answer 1

Reset to default 13

This works fine (with a single global marker object)

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

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

My guess is that you're interating, and your setTimeout i is not in scope. Try this instead:

    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);
}

There are some more creative solutions here:

Javascript how to use setTimeout on an iterative list operation?

发布评论

评论列表(0)

  1. 暂无评论