Skip to content

Commit afd61ac

Browse files
authored
Merge pull request #17 from sidraw27/master
let user can set section which should scrollto
2 parents f81f0a8 + ef91020 commit afd61ac

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function install (Vue, options) {
3535

3636
options = Object.assign({
3737
allowNoActive: false,
38+
sectionSelector: null,
3839
data: null,
3940
offset: 0,
4041
time: 500,
@@ -86,14 +87,15 @@ export default function install (Vue, options) {
8687
return 'default'
8788
}
8889

89-
function initScrollSections (el, selector) {
90+
function initScrollSections (el, sectionSelector) {
9091
const id = scrollSpyId(el)
91-
const idScrollSections = findElements(el, selector)
92+
const scrollSpyContext = el[scrollSpyContext]
93+
const idScrollSections = findElements(el, sectionSelector)
9294
scrollSpySections[id] = idScrollSections
9395

9496
if (idScrollSections[0] && idScrollSections[0].offsetParent !== el) {
95-
el[scrollSpyContext].eventEl = window
96-
el[scrollSpyContext].scrollEl = bodyScrollEl
97+
scrollSpyContext.eventEl = window
98+
scrollSpyContext.scrollEl = bodyScrollEl
9799
}
98100
}
99101

@@ -203,18 +205,17 @@ export default function install (Vue, options) {
203205
delete currentIndex[id]
204206
},
205207
inserted: function (el) {
206-
initScrollSections(el)
208+
const {eventEl, onScroll, options: {sectionSelector}} = el[scrollSpyContext]
207209

208-
const {eventEl, onScroll} = el[scrollSpyContext]
210+
initScrollSections(el, sectionSelector)
209211
eventEl.addEventListener('scroll', onScroll)
210212

211213
onScroll()
212214
},
213215
componentUpdated: function (el) {
214-
initScrollSections(el)
215-
216-
const {onScroll} = el[scrollSpyContext]
216+
const {onScroll, options: {sectionSelector}} = el[scrollSpyContext]
217217

218+
initScrollSections(el, sectionSelector)
218219
onScroll()
219220
},
220221
unbind: function (el) {

0 commit comments

Comments
 (0)