在谷歌地图中弹回一次图钉 [英] Bounce a pin in google maps once

查看:25
本文介绍了在谷歌地图中弹回一次图钉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在谷歌地图上弹一次图钉.下面的代码将使标记反弹,但它只是继续...

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

然后调用

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?

推荐答案

一个简单的方法:Google 的弹跳动画似乎在一个周期内恰好需要 750 毫秒.因此,只需将超时设置为 750 毫秒,动画就会在第一次弹跳结束时准确停止.适用于 FF 7、Chrome 14 和 IE 8:

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

这篇关于在谷歌地图中弹回一次图钉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆