Blame view

node_modules/better-scroll/src/util/momentum.js 959 Bytes
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  export function momentum(current, start, time, lowerMargin, upperMargin, wrapperSize, options) {
    let distance = current - start
    let speed = Math.abs(distance) / time
  
    let {deceleration, itemHeight, swipeBounceTime, wheel, swipeTime} = options
    let duration = swipeTime
    let rate = wheel ? 4 : 15
  
    let destination = current + speed / deceleration * (distance < 0 ? -1 : 1)
  
    if (wheel && itemHeight) {
      destination = Math.round(destination / itemHeight) * itemHeight
    }
  
    if (destination < lowerMargin) {
      destination = wrapperSize ? Math.max(lowerMargin - wrapperSize / 4, lowerMargin - (wrapperSize / rate * speed)) : lowerMargin
      duration = swipeBounceTime
    } else if (destination > upperMargin) {
      destination = wrapperSize ? Math.min(upperMargin + wrapperSize / 4, upperMargin + wrapperSize / rate * speed) : upperMargin
      duration = swipeBounceTime
    }
  
    return {
      destination: Math.round(destination),
      duration
    }
  }