Commit 72ba66620dbc64b92f5fa3bd43e734de0a0ba2a6
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,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,7 +121,14 @@ | @@ -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 | onCallback(dir) { | 130 | onCallback(dir) { |
| 131 | + console.log('onCallback', dir); | ||
| 119 | this.isLoading = true; | 132 | this.isLoading = true; |
| 120 | this.showBodyLoader = true; | 133 | this.showBodyLoader = true; |
| 121 | if (dir > 0) { | 134 | if (dir > 0) { |
| @@ -206,10 +219,10 @@ | @@ -206,10 +219,10 @@ | ||
| 206 | // to give the feeling its ruberish and can be puled more to start loading | 219 | // to give the feeling its ruberish and can be puled more to start loading |
| 207 | if (direction > 0 && this.reachedTopScrollLimit) { | 220 | if (direction > 0 && this.reachedTopScrollLimit) { |
| 208 | this.topRubberPadding += 5 - this.topRubberPadding / 5; | 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 | } else if (direction < 0 && this.reachedBottomScrollLimit) { | 223 | } else if (direction < 0 && this.reachedBottomScrollLimit) { |
| 211 | this.bottomRubberPadding += 6 - this.bottomRubberPadding / 4; | 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 | } else { | 226 | } else { |
| 214 | this.onScroll(); | 227 | this.onScroll(); |
| 215 | } | 228 | } |
| @@ -221,9 +234,11 @@ | @@ -221,9 +234,11 @@ | ||
| 221 | const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this | 234 | 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; | 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 | this.reachedBottomScrollLimit = true; | 240 | this.reachedBottomScrollLimit = true; |
| 226 | - } else if (scrollDirection >= 0 && el.scrollTop == 0) { | 241 | + } else if (scrollDirection >= 0 && el.scrollTop + topNegativeProximity <= 0) { |
| 227 | this.reachedTopScrollLimit = true; | 242 | this.reachedTopScrollLimit = true; |
| 228 | } else { | 243 | } else { |
| 229 | this.reachedTopScrollLimit = false; | 244 | this.reachedTopScrollLimit = false; |