vue-active-tracker v0.1.1
What are we talking about
This component simply let you change the class of your nav links depending on what element is in the view right now. This component should wrap you navigation and every link should have a reference a section of interest. See examples below..
How to install
npm install vue-active-trackerHow to use
import App from './App.vue';
import VActiveTracker from 'vue-active-tracker';
import Vue from 'vue';
Vue.use(VActiveTracker);
new Vue({
render: h => h(App),
}).$mount('#app');or without plugin initialization...
<template>
<v-active-tracker>
<nav>
<ul>
<li>
<a href="#first">First link</a>
</li>
<li>
<a href="#second">Second link</a>
</li>
<li>
<a href="#third">Third link</a>
</li>
</ul>
</nav>
</v-active-tracker>
...
<section id="first">
First section
</section>
<div id="second">
Second section
</div>
<footer id="third">
Third section
</footer>
</template>
<script>
import VActiveTracker from 'vue-active-tracker';
export default {
components: {
VActiveTracker
}
}
</script>Props
link-selector it is the selector used for finding nav links
- type:
String, default:
aDefine the selector used to find links (the search is limited for those links defined inside this component). See CSS selectors for more info. Examples: a, a.link, buttondata=foo, ...
- type:
active-class
- type:
String, default:
is-activeDefine which class (or classes) should be added when the link becomes active.
- type:
trigger
- type:
String, - default:
topDefine where do you want to place your trigger.. Possible values are the followingtopset the trigger at the top of the screen view (it is equivalent to 0% or 0)middleset the trigger at the vertical center of the screen view (its is equivalent to 50%)bottomset the trigger at the bottom of the screen view (its is equivalent to 100%){number}pxset the trigger {number} pixel from the top. Examples:100px,40px,10px, ...{number}equivalent of {number}px. Examples:100,40,10, ...{percentage}%set the trigger {percentage} percentage from the top where 0% means top and 100% means bottom. Examples:10%,20%,30%, ...
- type:
auto-start
- type:
Boolean, default:
trueWhen set to true the componets gets updated even when it is mounted the first time. Otherwise it will only update automatically when you resize window. You should always let this prop true.
- type:
Methods
update()
Use this method to re-bind links and sections as they are added to the DOM. The component, however, will auto udate whenever the page get resized.
Doubts ?
Doesn't work with conditionally displayed links
Try by using the
updatemethod after having added the link you want to the page.
License
MIT @ Davide Turrini (davide-turrini)