Blame view

node_modules/better-scroll/src/scroll/pullup.js 1.4 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  import { DIRECTION_UP, PROBE_REALTIME } from '../util/const'
  
  export function pullUpMixin(BScroll) {
    BScroll.prototype._initPullUp = function () {
      // must watch scroll in real time
      this.options.probeType = PROBE_REALTIME
  
      this.pullupWatching = false
      this._watchPullUp()
    }
  
    BScroll.prototype._watchPullUp = function () {
      if (this.pullupWatching) {
        return
      }
      this.pullupWatching = true
      this.on('scroll', this._checkToEnd)
    }
  
    BScroll.prototype._checkToEnd = function (pos) {
      const {threshold = 0} = this.options.pullUpLoad
      if (this.movingDirectionY === DIRECTION_UP && pos.y <= (this.maxScrollY + threshold)) {
        // reset pullupWatching status after scroll end.
        this.once('scrollEnd', () => {
          this.pullupWatching = false
        })
        this.trigger('pullingUp')
        this.off('scroll', this._checkToEnd)
      }
    }
  
    BScroll.prototype.finishPullUp = function () {
      if (this.pullupWatching) {
        this.once('scrollEnd', () => {
          this._watchPullUp()
        })
      } else {
        this._watchPullUp()
      }
    }
  
    BScroll.prototype.openPullUp = function (config = true) {
      this.options.pullUpLoad = config
      this._initPullUp()
    }
  
    BScroll.prototype.closePullUp = function () {
      this.options.pullUpLoad = false
      if (!this.pullupWatching) {
        return
      }
      this.pullupWatching = false
      this.off('scroll', this._checkToEnd)
    }
  }