Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let user can set section which should scrollto #17

Merged
merged 3 commits into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function install (Vue, options) {

options = Object.assign({
allowNoActive: false,
sectionSelector: null,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个值我觉得放在binding里比较好

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我找時間再看一下
現在只是讓我這邊能執行 還沒有考慮過
感謝您的幫忙!!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请看一下这样修改后是否能满足需求。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完全可以 感謝您的幫忙!!

data: null,
offset: 0,
time: 200,
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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) {
Expand Down