Skip to content

Commit

Permalink
improve animation
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Aug 27, 2016
1 parent 7d400fd commit dd166d5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ let defineProperty = Object.defineProperty
* @param {Object} opts
* @api public
*/
class Iscroll {
class Iscroll extends Emitter {
constructor(el, opts) {
super()
this.y = 0
this.scrollable = el
el.style.overflow = 'hidden'
Expand Down Expand Up @@ -254,23 +255,22 @@ class Iscroll {
momentum() {
let deceleration = 0.001
let speed = this.speed
speed = min(speed, 2)
speed = min(speed, 4)
let y = this.y
let rate = (4 - Math.PI)/2
let destination = y + rate * (speed * speed) / (2 * deceleration) * (this.distance < 0 ? -1 : 1)
let duration = speed / deceleration
let ease
let minY = this.minY
if (y > 0 || y < minY) {
duration = 500
duration = 300
ease = 'out-circ'
destination = y > 0 ? 0 : minY
} else if (destination > 0) {
destination = 0
ease = 'out-back'
} else if (destination < minY) {
destination = minY
ease = 'out-back'
} else if (destination > 0 || destination < minY) {
let dis = destination - y
ease = outBack
destination = destination > 0 ? 0 : minY
duration = (1 - Math.abs((destination - y)/dis))*duration
}
return {
dest: destination,
Expand Down Expand Up @@ -438,6 +438,9 @@ class Iscroll {
}
}

Emitter(Iscroll.prototype)
function outBack(n) {
var s = 1.20158;
return --n * n * ((s + 1) * n + s) + 1;
}

export default Iscroll

0 comments on commit dd166d5

Please sign in to comment.