From c94c52a31c98ca10a2671469fccca131bca56df0 Mon Sep 17 00:00:00 2001 From: SiDraw Date: Wed, 11 Apr 2018 12:16:27 +0800 Subject: [PATCH 1/3] let user can set section which should scrollto --- src/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 4f92f4f..7e6788a 100644 --- a/src/index.js +++ b/src/index.js @@ -33,6 +33,7 @@ export default function install (Vue, options) { options = Object.assign({ allowNoActive: false, + sectionSelector: null, data: null, offset: 0, time: 200, @@ -83,14 +84,15 @@ export default function install (Vue, options) { return 'default' } - function initScrollSections (el, selector) { + function initScrollSections (el) { const id = scrollSpyId(el) - const idScrollSections = findElements(el, selector) + const sectionEl = el[scrollSpyContext] + const idScrollSections = findElements(el, sectionEl.options.sectionSelector) scrollSpySections[id] = idScrollSections if (idScrollSections[0] && idScrollSections[0].offsetParent !== el) { - el[scrollSpyContext].eventEl = window - el[scrollSpyContext].scrollEl = bodyScrollEl + sectionEl.eventEl = window + sectionEl.scrollEl = bodyScrollEl } } From 4a54abe64afe4a1640ac51e6602b16611d5ca2fa Mon Sep 17 00:00:00 2001 From: morning Date: Mon, 16 Apr 2018 17:16:46 +0800 Subject: [PATCH 2/3] use sectionSelector from bind.value --- src/index.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index 7e6788a..8484cbb 100644 --- a/src/index.js +++ b/src/index.js @@ -84,15 +84,15 @@ export default function install (Vue, options) { return 'default' } - function initScrollSections (el) { + function initScrollSections (el, sectionSelector) { const id = scrollSpyId(el) - const sectionEl = el[scrollSpyContext] - const idScrollSections = findElements(el, sectionEl.options.sectionSelector) + const scrollSpyContext = el[scrollSpyContext] + const idScrollSections = findElements(el, sectionSelector) scrollSpySections[id] = idScrollSections if (idScrollSections[0] && idScrollSections[0].offsetParent !== el) { - sectionEl.eventEl = window - sectionEl.scrollEl = bodyScrollEl + scrollSpyContext.eventEl = window + scrollSpyContext.scrollEl = bodyScrollEl } } @@ -196,18 +196,17 @@ export default function install (Vue, options) { scrollSpyElements[id] = el }, inserted: function (el) { - initScrollSections(el) - - const {eventEl, onScroll} = el[scrollSpyContext] + const {eventEl, onScroll, options: {sectionSelector}} = el[scrollSpyContext] + + initScrollSections(el, sectionSelector) eventEl.addEventListener('scroll', onScroll) onScroll() }, componentUpdated: function (el) { - initScrollSections(el) - - const {onScroll} = el[scrollSpyContext] - + const {onScroll, options: {sectionSelector}} = el[scrollSpyContext] + + initScrollSections(el, sectionSelector) onScroll() }, unbind: function (el) { From ef910200d12117e02f1f43a5f0d911d13e55f1ab Mon Sep 17 00:00:00 2001 From: morning Date: Mon, 16 Apr 2018 17:18:27 +0800 Subject: [PATCH 3/3] remove space --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8484cbb..c779b2a 100644 --- a/src/index.js +++ b/src/index.js @@ -197,7 +197,7 @@ export default function install (Vue, options) { }, inserted: function (el) { const {eventEl, onScroll, options: {sectionSelector}} = el[scrollSpyContext] - + initScrollSections(el, sectionSelector) eventEl.addEventListener('scroll', onScroll) @@ -205,7 +205,7 @@ export default function install (Vue, options) { }, componentUpdated: function (el) { const {onScroll, options: {sectionSelector}} = el[scrollSpyContext] - + initScrollSections(el, sectionSelector) onScroll() },