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,9 +54,11 @@
54 }, 54 },
55 loadingText: { 55 loadingText: {
56 type: String 56 type: String
57 - } 57 + },
  58 + distanceToEdge: [Number, Array]
58 }, 59 },
59 data() { 60 data() {
  61 + const distanceToEdge = this.calculateProximityThreshold();
60 return { 62 return {
61 showTopLoader: false, 63 showTopLoader: false,
62 showBottomLoader: false, 64 showBottomLoader: false,
@@ -73,6 +75,10 @@ @@ -73,6 +75,10 @@
73 handleScroll: () => {}, 75 handleScroll: () => {},
74 pointerUpHandler: () => {}, 76 pointerUpHandler: () => {},
75 pointerMoveHandler: () => {}, 77 pointerMoveHandler: () => {},
  78 +
  79 + // near to edge detectors
  80 + topProximityThreshold: distanceToEdge[0],
  81 + bottomProximityThreshold: distanceToEdge[1]
76 }; 82 };
77 }, 83 },
78 computed: { 84 computed: {
@@ -115,6 +121,12 @@ @@ -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 onCallback(dir) { 130 onCallback(dir) {
119 this.isLoading = true; 131 this.isLoading = true;
120 this.showBodyLoader = true; 132 this.showBodyLoader = true;
@@ -206,10 +218,10 @@ @@ -206,10 +218,10 @@
206 // to give the feeling its ruberish and can be puled more to start loading 218 // to give the feeling its ruberish and can be puled more to start loading
207 if (direction > 0 && this.reachedTopScrollLimit) { 219 if (direction > 0 && this.reachedTopScrollLimit) {
208 this.topRubberPadding += 5 - this.topRubberPadding / 5; 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 } else if (direction < 0 && this.reachedBottomScrollLimit) { 222 } else if (direction < 0 && this.reachedBottomScrollLimit) {
211 this.bottomRubberPadding += 6 - this.bottomRubberPadding / 4; 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 } else { 225 } else {
214 this.onScroll(); 226 this.onScroll();
215 } 227 }
@@ -221,9 +233,11 @@ @@ -221,9 +233,11 @@
221 const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this 233 const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this
222 const displacement = el.scrollHeight - el.clientHeight - el.scrollTop; 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 this.reachedBottomScrollLimit = true; 239 this.reachedBottomScrollLimit = true;
226 - } else if (scrollDirection >= 0 && el.scrollTop == 0) { 240 + } else if (scrollDirection >= 0 && el.scrollTop + topNegativeProximity <= 0) {
227 this.reachedTopScrollLimit = true; 241 this.reachedTopScrollLimit = true;
228 } else { 242 } else {
229 this.reachedTopScrollLimit = false; 243 this.reachedTopScrollLimit = false;