【问题标题】:javascript: how to implement animation?javascript:如何实现动画?
【发布时间】:2012-08-20 10:39:05
【问题描述】:

我在我的项目中使用 Google Maps Javascript API V3。我想将标记从一个位置动画移动到另一个位置。我可以通过

更新标记的位置
marker.setPosition(newPosition)

但是如何平滑地移动标记呢?

【问题讨论】:

    标签: javascript google-maps animation jquery-animate


    【解决方案1】:
    var startPos, curPos, endPos, delta; // set these values
    var interval;
    
    curPos = startPos;
    
    function move() {
        marker.setPosition(curPos);
    
        if ( curPos < endPos ) {
           if ( curPos + delta > endPos ) curPos = endPos - curPos;
           else curPos += delta;
    
           setTimeout(move, interval);
        }
    }
    
    move();
    

    curPosstartPosendPosdeltagoogle.maps.LatLng 的实例

    【讨论】:

      猜你喜欢
      • 2012-10-14
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      相关资源
      最近更新 更多