From 72ba66620dbc64b92f5fa3bd43e734de0a0ba2a6 Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Wed, 25 Oct 2017 21:21:35 +0200 Subject: [PATCH 1/2] add distance-to-edge property --- src/components/scroll/scroll.vue | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/scroll/scroll.vue b/src/components/scroll/scroll.vue index 039a8c8a..8e536309 100644 --- a/src/components/scroll/scroll.vue +++ b/src/components/scroll/scroll.vue @@ -54,9 +54,11 @@ }, loadingText: { type: String - } + }, + distanceToEdge: [Number, Array] }, data() { + const distanceToEdge = this.calculateProximityThreshold(); return { showTopLoader: false, showBottomLoader: false, @@ -73,6 +75,10 @@ handleScroll: () => {}, pointerUpHandler: () => {}, pointerMoveHandler: () => {}, + + // near to edge detectors + topProximityThreshold: distanceToEdge[0], + bottomProximityThreshold: distanceToEdge[1] }; }, computed: { @@ -115,7 +121,14 @@ }); }, + calculateProximityThreshold(){ + const dte = this.distanceToEdge; + if (typeof dte == 'undefined') return [20, 20]; + return Array.isArray(dte) ? dte : [dte, dte]; + }, + onCallback(dir) { + console.log('onCallback', dir); this.isLoading = true; this.showBodyLoader = true; if (dir > 0) { @@ -206,10 +219,10 @@ // to give the feeling its ruberish and can be puled more to start loading if (direction > 0 && this.reachedTopScrollLimit) { this.topRubberPadding += 5 - this.topRubberPadding / 5; - if (this.topRubberPadding > 20) this.onCallback(1); + if (this.topRubberPadding > this.topProximityThreshold) this.onCallback(1); } else if (direction < 0 && this.reachedBottomScrollLimit) { this.bottomRubberPadding += 6 - this.bottomRubberPadding / 4; - if (this.bottomRubberPadding > 20) this.onCallback(-1); + if (this.bottomRubberPadding > this.bottomProximityThreshold) this.onCallback(-1); } else { this.onScroll(); } @@ -221,9 +234,11 @@ const scrollDirection = Math.sign(this.lastScroll - el.scrollTop); // IE has no Math.sign, check that webpack polyfills this const displacement = el.scrollHeight - el.clientHeight - el.scrollTop; - if (scrollDirection == -1 && displacement <= dragConfig.sensitivity) { + const topNegativeProximity = this.topProximityThreshold < 0 ? this.topProximityThreshold : 0; + const bottomNegativeProximity = this.bottomProximityThreshold < 0 ? this.bottomProximityThreshold : 0; + if (scrollDirection == -1 && displacement + bottomNegativeProximity <= dragConfig.sensitivity) { this.reachedBottomScrollLimit = true; - } else if (scrollDirection >= 0 && el.scrollTop == 0) { + } else if (scrollDirection >= 0 && el.scrollTop + topNegativeProximity <= 0) { this.reachedTopScrollLimit = true; } else { this.reachedTopScrollLimit = false; From 19ad5f4deaef3b5a3b4f5e6fda1bba98612ec9d1 Mon Sep 17 00:00:00 2001 From: Aresn Date: Thu, 26 Oct 2017 00:14:36 -0500 Subject: [PATCH 2/2] Update scroll.vue --- src/components/scroll/scroll.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/scroll/scroll.vue b/src/components/scroll/scroll.vue index 8e536309..47cc3828 100644 --- a/src/components/scroll/scroll.vue +++ b/src/components/scroll/scroll.vue @@ -128,7 +128,6 @@ }, onCallback(dir) { - console.log('onCallback', dir); this.isLoading = true; this.showBodyLoader = true; if (dir > 0) {