Commit 72ba66620dbc64b92f5fa3bd43e734de0a0ba2a6

Authored by Sergio Crisostomo
1 parent af7d72b4

add distance-to-edge property

Showing 1 changed file with 20 additions and 5 deletions   Show diff stats
src/components/scroll/scroll.vue
... ... @@ -54,9 +54,11 @@
54 54 },
55 55 loadingText: {
56 56 type: String
57   - }
  57 + },
  58 + distanceToEdge: [Number, Array]
58 59 },
59 60 data() {
  61 + const distanceToEdge = this.calculateProximityThreshold();
60 62 return {
61 63 showTopLoader: false,
62 64 showBottomLoader: false,
... ... @@ -73,6 +75,10 @@
73 75 handleScroll: () => {},
74 76 pointerUpHandler: () => {},
75 77 pointerMoveHandler: () => {},
  78 +
  79 + // near to edge detectors
  80 + topProximityThreshold: distanceToEdge[0],
  81 + bottomProximityThreshold: distanceToEdge[1]
76 82 };
77 83 },
78 84 computed: {
... ... @@ -115,7 +121,14 @@
115 121 });
116 122 },
117 123  
  124 + calculateProximityThreshold(){
  125 + const dte = this.distanceToEdge;
  126 + if (typeof dte == 'undefined') return [20, 20];
  127 + return Array.isArray(dte) ? dte : [dte, dte];
  128 + },
  129 +
118 130 onCallback(dir) {
  131 + console.log('onCallback', dir);
119 132 this.isLoading = true;
120 133 this.showBodyLoader = true;
121 134 if (dir > 0) {
... ... @@ -206,10 +219,10 @@
206 219 // to give the feeling its ruberish and can be puled more to start loading
207 220 if (direction > 0 && this.reachedTopScrollLimit) {
208 221 this.topRubberPadding += 5 - this.topRubberPadding / 5;
209   - if (this.topRubberPadding > 20) this.onCallback(1);
  222 + if (this.topRubberPadding > this.topProximityThreshold) this.onCallback(1);
210 223 } else if (direction < 0 && this.reachedBottomScrollLimit) {
211 224 this.bottomRubberPadding += 6 - this.bottomRubberPadding / 4;
212   - if (this.bottomRubberPadding > 20) this.onCallback(-1);
  225 + if (this.bottomRubberPadding > this.bottomProximityThreshold) this.onCallback(-1);
213 226 } else {
214 227 this.onScroll();
215 228 }
... ... @@ -221,9 +234,11 @@
221 234 const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this
222 235 const displacement = el.scrollHeight - el.clientHeight - el.scrollTop;
223 236  
224   - if (scrollDirection == -1 && displacement <= dragConfig.sensitivity) {
  237 + const topNegativeProximity = this.topProximityThreshold < 0 ? this.topProximityThreshold : 0;
  238 + const bottomNegativeProximity = this.bottomProximityThreshold < 0 ? this.bottomProximityThreshold : 0;
  239 + if (scrollDirection == -1 && displacement + bottomNegativeProximity <= dragConfig.sensitivity) {
225 240 this.reachedBottomScrollLimit = true;
226   - } else if (scrollDirection >= 0 && el.scrollTop == 0) {
  241 + } else if (scrollDirection >= 0 && el.scrollTop + topNegativeProximity <= 0) {
227 242 this.reachedTopScrollLimit = true;
228 243 } else {
229 244 this.reachedTopScrollLimit = false;
... ...