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

feat: Add option to specify when the menu active class is triggered #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ section index.
2. `v-scroll-spy="{allowNoActive: true}"`: allow no active sections when scroll position is outside of the scrollspy
container. Default behavior is too keep active at least one section in any case.

3. `v-scroll-spy="{offset: 50}"`: add an offset for scroll and active events.
3. `v-scroll-spy="{offset: 50}"`: add an offset for scroll events.

4. `v-scroll-spy="{time: 200, steps: 30}"`: set the animation options.
4. `v-scroll-spy="{menuTriggerOffset: 50}"`: offset to trigger the menu active class (defaults to offset if not provided).

5. `$scrollTo(index: int)` is provided on scope Vue instance to invoke a scroll to the given section index.
5. `v-scroll-spy="{time: 200, steps: 30}"`: set the animation options.

6. `v-section-selector`: set section which should scrollto
6. `$scrollTo(index: int)` is provided on scope Vue instance to invoke a scroll to the given section index.

7. `v-section-selector`: set section which should scrollto

### **v-scroll-spy-active**

Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ const install = (Vue, options) => {
const activableElements = {}
const currentIndex = {}

// set menuTriggerOffset based on offset (for backwards compatibility)
const menuTriggerOffset = options
&& typeof options === 'object'
&& 'offset' in options
? options.offset
: 0;

options = Object.assign({
allowNoActive: false,
sectionSelector: null,
data: null,
offset: 0,
menuTriggerOffset: menuTriggerOffset,
time: 500,
steps: 30,
easing: null,
Expand Down Expand Up @@ -153,7 +161,7 @@ const install = (Vue, options) => {
index = idScrollSections.length
} else {
for (index = 0; index < idScrollSections.length; index++) {
if (getOffsetTop(idScrollSections[index], scrollEl) - options.offset > scrollEl.scrollTop) {
if (getOffsetTop(idScrollSections[index], scrollEl) - options.menuTriggerOffset > scrollEl.scrollTop) {
break
}
}
Expand Down