From 170d0b51dc15df734a408c5006e5c664a98eeff0 Mon Sep 17 00:00:00 2001 From: tmcdos Date: Fri, 28 Sep 2018 11:13:53 +0300 Subject: [PATCH] 1) scrollbar size is recalculated when the component is updated (usually content is added or removed) 2) width of horizontal scrollbar is reduced from 100% when the vertical scrollbar is visible to avoid their mutual overlapping 3) height of vertical scrollbar is reduced from 100% when the horizontal scrollbar is visible to avoid their overlapping 4) scrollbar position is properly updated when it was at 100% and inner content was removed (otherwise you can no longer scroll - the slider gets stuck at the end) 5) got rid of document listeners - they are needless as we only want to scroll our container, not the whole page 6) added ability for auto-scrolling (e.g. when used in combination with Vue2-Dragula) 7) added ability to prevent scrolling on mobile (e.g. when dragging items through Vue2-Dragula) - otherwise the scrolling takes precedence over dragging (on mobile only) 8) added computed properties to show whether the horizontal or vertical scrollbars are currently visible 10) the component emits events during scrolling - "scrollx" for horizontal, "scrolly" for vertical and "scroll" for any of them --- src/js/components/horizontal-scrollbar.vue | 356 ++++----- src/js/components/vertical-scrollbar.vue | 367 +++++----- src/js/components/vue-scrollbar.vue | 812 +++++++++++++-------- 3 files changed, 872 insertions(+), 663 deletions(-) diff --git a/src/js/components/horizontal-scrollbar.vue b/src/js/components/horizontal-scrollbar.vue index aeb2b73..f21b5e9 100644 --- a/src/js/components/horizontal-scrollbar.vue +++ b/src/js/components/horizontal-scrollbar.vue @@ -1,163 +1,193 @@ - - - - + + + + diff --git a/src/js/components/vertical-scrollbar.vue b/src/js/components/vertical-scrollbar.vue index dc7bb07..3cbbd0e 100644 --- a/src/js/components/vertical-scrollbar.vue +++ b/src/js/components/vertical-scrollbar.vue @@ -1,179 +1,188 @@ - - - - + + + + diff --git a/src/js/components/vue-scrollbar.vue b/src/js/components/vue-scrollbar.vue index 3e15c22..a6af5a7 100644 --- a/src/js/components/vue-scrollbar.vue +++ b/src/js/components/vue-scrollbar.vue @@ -1,322 +1,492 @@ - - - - - + })); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} + }, + mounted () { + this.calculateSize() + + // Attach The Event for Responsive View + window.addEventListener('resize', this.calculateSize) + document.addEventListener('mousemove', this.checkAutoScroll, false) + document.addEventListener('touchmove', this.checkAutoScroll, this.supportsPassive ? {passive: false} : false) + }, + + updated () + { + const self = this; + this.$nextTick(function() + { + setTimeout(function() + { + self.calculateSize() + },50) + }) + }, + + beforeDestroy (){ + // Remove Event + window.removeEventListener('resize', this.calculateSize) + document.removeEventListener('mousemove', this.checkAutoScroll) + document.removeEventListener('touchmove', this.checkAutoScroll) + } + + } + + + +