Bounce a pin in google maps once

2019-01-30 20:07发布

I want to bounce a pin on a google map once. The following code will make the marker bounce but it just keeps going...

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

Then calling

myPin.setAnimation(null);

makes the animation stop. Setting a timeout works but the duration of a bounce doesn't look like it is a round number so doing this

  setTimeout(function(){ myPin.setAnimation(null); }, 1000);

Make the bounce animation end prematurely and look terrible.

Does anyone know of a better way to accomplish this?

9条回答
男人必须洒脱
2楼-- · 2019-01-30 20:15

Thanks, for the good answer, I just integrated adding a bit of millisenconds

function toggleBounce(currentIcon) {
 currentIcon.setAnimation(null);

if (currentIcon.getAnimation() != null) {
  currentIcon.setAnimation(null);
 } else {
   currentIcon.setAnimation(google.maps.Animation.BOUNCE);
   setTimeout(function(){ currentIcon.setAnimation(null); }, 900);
 }
};
查看更多
够拽才男人
3楼-- · 2019-01-30 20:16

At the moment there is no built in animation for bouncing once.

If you are OK with it bouncing twice then i strongly suggest that you use this:

marker.setAnimation(4);

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-30 20:17
  marker.setAnimation(google.maps.Animation.BOUNCE);
        setTimeout(function() {
             marker.setAnimation(null)
        }, 6000);
查看更多
神经病院院长
5楼-- · 2019-01-30 20:21

Bit of a simple approach: Google's bounce animation appears to take exactly 750 ms for one cycle. Thus, simply set the timeout to 750 ms and the animation will stop exactly at the end of the first bounce. Works for me on FF 7, Chrome 14 and IE 8:

    marker.setAnimation(google.maps.Animation.BOUNCE);
    setTimeout(function(){ marker.setAnimation(null); }, 750);
查看更多
我只想做你的唯一
6楼-- · 2019-01-30 20:25

use this code:

animation:google.maps.Animation.DROP
查看更多
Melony?
7楼-- · 2019-01-30 20:26

Just a note: if you're triggering this on multiple markers, you'll want to check to make sure the marker's not currently animating by adding the following code before you call marker.setAnimation( google.maps.Animation.BOUNCE );:

if( marker.animating ) { return; }

查看更多
登录 后发表回答