Elffuss BraidHub

kikocis/iscroll public

b4fcff1d26dc · 717 BRawPermalink
1
2 _animate: function (destX, destY, duration, easingFn) {
3 var that = this,
4 startX = this.x,
5 startY = this.y,
6 startTime = utils.getTime(),
7 destTime = startTime + duration;
8
9 function step () {
10 var now = utils.getTime(),
11 newX, newY,
12 easing;
13
14 if ( now >= destTime ) {
15 that.isAnimating = false;
16 that._translate(destX, destY);
17 that.resetPosition(that.options.bounceTime);
18 return;
19 }
20
21 now = ( now - startTime ) / duration;
22 easing = easingFn(now);
23 newX = ( destX - startX ) * easing + startX;
24 newY = ( destY - startY ) * easing + startY;
25 that._translate(newX, newY);
26
27 if ( that.isAnimating ) {
28 rAF(step);
29 }
30 }
31
32 this.isAnimating = true;
33 step();
34 },