diff --git a/package-lock.json b/package-lock.json index 3198e5e..13dc287 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vue2-scrollspy", - "version": "2.0.1", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/index.js b/src/index.js index 3901111..45b34f4 100644 --- a/src/index.js +++ b/src/index.js @@ -85,9 +85,16 @@ export default function install (Vue, options) { function initScrollSections (el, selector) { const id = scrollSpyId(el) - const idScrollSections = findElements(el, selector) + const idScrollSections = findElements(el) scrollSpySections[id] = idScrollSections + if (selector) { + const dom = document.querySelector(selector) + el[scrollSpyContext].eventEl = dom + el[scrollSpyContext].scrollEl = dom + return + } + if (idScrollSections[0] && idScrollSections[0].offsetParent !== el) { el[scrollSpyContext].eventEl = window el[scrollSpyContext].scrollEl = bodyScrollEl @@ -193,16 +200,16 @@ export default function install (Vue, options) { scrollSpyElements[id] = el }, - inserted: function (el) { - initScrollSections(el) + inserted: function (el, binding) { + initScrollSections(el, binding.value.container) const {eventEl, onScroll} = el[scrollSpyContext] eventEl.addEventListener('scroll', onScroll) onScroll() }, - componentUpdated: function (el) { - initScrollSections(el) + componentUpdated: function (el, binding) { + initScrollSections(el, binding.value.container) const {onScroll} = el[scrollSpyContext]