diff --git a/src/index.js b/src/index.js index 4f92f4f..c779b2a 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, sectionSelector) { const id = scrollSpyId(el) - const idScrollSections = findElements(el, selector) + const scrollSpyContext = el[scrollSpyContext] + const idScrollSections = findElements(el, sectionSelector) scrollSpySections[id] = idScrollSections if (idScrollSections[0] && idScrollSections[0].offsetParent !== el) { - el[scrollSpyContext].eventEl = window - el[scrollSpyContext].scrollEl = bodyScrollEl + scrollSpyContext.eventEl = window + scrollSpyContext.scrollEl = bodyScrollEl } } @@ -194,18 +196,17 @@ export default function install (Vue, options) { scrollSpyElements[id] = el }, inserted: function (el) { - initScrollSections(el) + const {eventEl, onScroll, options: {sectionSelector}} = el[scrollSpyContext] - const {eventEl, onScroll} = 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) {