A Vue.js directive to add a class to an based on vertical scroll.
npm i -S vue-scroll-class
import VueScrollClass from 'vue-scroll-class';
Register to Vue globally:
Vue.directives('scroll-class': VueScrollClass);
Register to a specific Vue instance:
const app = new Vue({
...
directives: {
'scroll-class': VueScrollClass,
},
...
});
vue-scroll-class defaults to adding the class 'sticky' to the attached element after the page has been scrolled 100px:
<div v-scroll-class>I'll get the class 'sticky' after 100px!</div>
To override these defaults, add a class name or a different number of pixels in the appropriate place:
<div v-scroll-class:differentClass=645>I'll get the class 'differentClass' after 645px!></div>