Skip to content

Commit

Permalink
Merge pull request #17 from sidraw27/master
Browse files Browse the repository at this point in the history
let user can set section which should scrollto
  • Loading branch information
ibufu authored Apr 16, 2018
2 parents f81f0a8 + ef91020 commit afd61ac
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function install (Vue, options) {

options = Object.assign({
allowNoActive: false,
sectionSelector: null,
data: null,
offset: 0,
time: 500,
Expand Down Expand Up @@ -86,14 +87,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
}
}

Expand Down Expand Up @@ -203,18 +205,17 @@ export default function install (Vue, options) {
delete currentIndex[id]
},
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) {
Expand Down

0 comments on commit afd61ac

Please sign in to comment.