Vue2 Smooth Scroll
Lightweight Vue plugin for smooth-scrolling extended from vue-smooth-scroll.
For simple use-cases, the native scroll-behavior
CSS property (working draft) may be enough.
This package compatible with Vue 2.x and Vue 1.x
New package for Vue 3.x use this package v-smooth-scroll
Features
- Directive and programmatic API with global and local config overrides
- SSR
- Smooth, non-blocking animation using
requestAnimationFrame
(with fallback) - Y-axis or vertical scrolling
- Specific scroll containers
- 1.3kB gzipped, 2.9kB min
Installation
npm install --save vue2-smooth-scroll
import VueSmoothScroll from 'vue2-smooth-scroll'
Vue.use(VueSmoothScroll)
Usage
Directive
<a href="#sec-3" v-smooth-scroll>Section 3a>
<section id="sec-3">section>
Programmatic
const myEl = this.$refs.myEl || this.$el || document.getElementById(...)
this.$smoothScroll({
scrollTo: myEl,
hash: '#sampleHash' // required if updateHistory is true
})