Commit 86cdfb872c4d05b10426c5483bfdde8f1c52556e

Authored by Aresn
Committed by GitHub
2 parents 252717e7 19ad5f4d

Merge pull request #2194 from SergioCrisostomo/add-scroll-distance-to-edge

add distance-to-edge property
Showing 1 changed file with 19 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,6 +121,12 @@
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) {
119 131 this.isLoading = true;
120 132 this.showBodyLoader = true;
... ... @@ -206,10 +218,10 @@
206 218 // to give the feeling its ruberish and can be puled more to start loading
207 219 if (direction > 0 && this.reachedTopScrollLimit) {
208 220 this.topRubberPadding += 5 - this.topRubberPadding / 5;
209   - if (this.topRubberPadding > 20) this.onCallback(1);
  221 + if (this.topRubberPadding > this.topProximityThreshold) this.onCallback(1);
210 222 } else if (direction < 0 && this.reachedBottomScrollLimit) {
211 223 this.bottomRubberPadding += 6 - this.bottomRubberPadding / 4;
212   - if (this.bottomRubberPadding > 20) this.onCallback(-1);
  224 + if (this.bottomRubberPadding > this.bottomProximityThreshold) this.onCallback(-1);
213 225 } else {
214 226 this.onScroll();
215 227 }
... ... @@ -221,9 +233,11 @@
221 233 const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this
222 234 const displacement = el.scrollHeight - el.clientHeight - el.scrollTop;
223 235  
224   - if (scrollDirection == -1 && displacement <= dragConfig.sensitivity) {
  236 + const topNegativeProximity = this.topProximityThreshold < 0 ? this.topProximityThreshold : 0;
  237 + const bottomNegativeProximity = this.bottomProximityThreshold < 0 ? this.bottomProximityThreshold : 0;
  238 + if (scrollDirection == -1 && displacement + bottomNegativeProximity <= dragConfig.sensitivity) {
225 239 this.reachedBottomScrollLimit = true;
226   - } else if (scrollDirection >= 0 && el.scrollTop == 0) {
  240 + } else if (scrollDirection >= 0 && el.scrollTop + topNegativeProximity <= 0) {
227 241 this.reachedTopScrollLimit = true;
228 242 } else {
229 243 this.reachedTopScrollLimit = false;
... ...