| 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 | |
| 18 | if ( !that.resetPosition(that.options.bounceTime) ) { |
| 19 | that._execEvent('scrollEnd'); |
| 20 | } |
| 21 | |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | now = ( now - startTime ) / duration; |
| 26 | easing = easingFn(now); |
| 27 | newX = ( destX - startX ) * easing + startX; |
| 28 | newY = ( destY - startY ) * easing + startY; |
| 29 | that._translate(newX, newY); |
| 30 | |
| 31 | if ( that.isAnimating ) { |
| 32 | rAF(step); |
| 33 | } |
| 34 | |
| 35 | if ( that.options.probeType == 3 ) { |
| 36 | that._execEvent('scroll'); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | this.isAnimating = true; |
| 41 | step(); |
| 42 | }, |