Gathering detailed insights and metrics for vue-scrollto
Gathering detailed insights and metrics for vue-scrollto
Gathering detailed insights and metrics for vue-scrollto
Gathering detailed insights and metrics for vue-scrollto
Adds a directive that listens for click events and scrolls to elements.
npm install vue-scrollto
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,071 Stars
499 Commits
99 Forks
16 Watching
45 Branches
31 Contributors
Updated on 20 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.9%
23,360
Compared to previous day
Last week
-2.6%
126,306
Compared to previous week
Last month
12.5%
553,559
Compared to previous month
Last year
-12.7%
6,183,421
Compared to previous year
1
Scrolling to elements was never this easy!
This is for vue 2.x
and vue 3.x
(since v2.19.0
)
For vue 1.x
use vue-scrollTo@1.0.1
(note the capital T) but keep in mind that the old version depends on jquery
.
vue-scrollto
uses window.requestAnimationFrame
to perform the animations, thus giving the best performance.
Easing is done using bezier-easing - A well tested easing micro-library.
It even knows when the user interrupts, and doesn't force scrolling that would result in bad UX.
This package is available on npm.
If you used this package before, please ensure you are using the right one, since it has been renamed from `vue-scrollTo` to `vue-scrollto`
Using npm:
1npm install --save vue-scrollto
Using yarn:
1yarn add vue-scrollto
Directly include it in html:
1<script src="https://cdn.jsdelivr.net/npm/vue"></script> 2<script src="https://cdn.jsdelivr.net/npm/vue-scrollto"></script>
When including it in html, it will automatically call `Vue.use` and also set a `VueScrollTo` variable that you can use!
Add vue-scrollto/nuxt
to modules section of nuxt.config.js
1{ 2 modules: [ 3 'vue-scrollto/nuxt', 4 5 // Or if you have custom options... 6 ['vue-scrollto/nuxt', { duration: 300 }], 7 ] 8}
vue-scrollto can be used either as a vue directive, or programatically from your javascript.
1var Vue = require('vue'); 2var VueScrollTo = require('vue-scrollto'); 3 4Vue.use(VueScrollTo) 5 6// You can also pass in the default options 7Vue.use(VueScrollTo, { 8 container: "body", 9 duration: 500, 10 easing: "ease", 11 offset: 0, 12 force: true, 13 cancelable: true, 14 onStart: false, 15 onDone: false, 16 onCancel: false, 17 x: false, 18 y: true 19 })
In case you are using the browser version (directly including the script on your page), you can set the defaults with
1VueScrollTo.setDefaults({
2 container: "body",
3 duration: 500,
4 lazy: false,
5 easing: "ease",
6 offset: 0,
7 force: true,
8 cancelable: true,
9 onStart: false,
10 onDone: false,
11 onCancel: false,
12 x: false,
13 y: true
14})
1<a href="#" v-scroll-to="'#element'">Scroll to #element</a> 2 3<div id="element"> 4 Hi. I'm #element. 5</div>
If you need to customize the scrolling options, you can pass in an object literal to the directive:
1<a href="#" v-scroll-to="{ 2 el: '#element', 3 container: '#container', 4 duration: 500, 5 lazy: false 6 easing: 'linear', 7 offset: -200, 8 force: true, 9 cancelable: true, 10 onStart: onStart, 11 onDone: onDone, 12 onCancel: onCancel, 13 x: false, 14 y: true 15 }"> 16 Scroll to #element 17</a>
Check out the Options section for more details about the available options.
1var VueScrollTo = require('vue-scrollto'); 2 3var options = { 4 container: '#container', 5 easing: 'ease-in', 6 lazy: false, 7 offset: -60, 8 force: true, 9 cancelable: true, 10 onStart: function(element) { 11 // scrolling started 12 }, 13 onDone: function(element) { 14 // scrolling is done 15 }, 16 onCancel: function() { 17 // scrolling has been interrupted 18 }, 19 x: false, 20 y: true 21} 22 23var cancelScroll = VueScrollTo.scrollTo(element, duration, options) 24 25// or alternatively inside your components you can use 26cancelScroll = this.$scrollTo(element, duration, options) 27 28// to cancel scrolling you can call the returned function 29cancelScroll()
The element you want to scroll to.
The container that has to be scrolled.
Default: body
The duration (in milliseconds) of the scrolling animation.
Default: 500
The easing to be used when animating. Read more in the Easing section.
Default: ease
By default targetX/targetY are calculated once at the start of a scroll, however if the target may shift around during the scroll - setting lazy
to false
will force recalculation of targetX/targetY at each scroll step.
Default: true
The offset that should be applied when scrolling. This option accepts a callback function since v2.8.0
.
Default: 0
Indicates if scrolling should be performed, even if the scroll target is already in view.
Default: true
Indicates if user can cancel the scroll or not.
Default: true
A callback function that should be called when scrolling has started. Receives the target element as a parameter.
Default: noop
A callback function that should be called when scrolling has ended. Receives the target element as a parameter.
Default: noop
A callback function that should be called when scrolling has been aborted by the user (user scrolled, clicked etc.). Receives the abort event and the target element as parameters.
Default: noop
Whether or not we want scrolling on the x
axis
Default: false
Whether or not we want scrolling on the y
axis
Default: true
Easing is calculated using bezier-easing so you can pass your own values into options.easing
in the form of an array with 4 values, or you can use any of the default easings by referencing their names as strings (ease
, linear
, ease-in
, ease-out
, ease-in-out
).
vue-scrollto uses the following values for the default easings:
1let easings = { 2 'ease': [0.25, 0.1, 0.25, 1.0], 3 'linear': [0.00, 0.0, 1.00, 1.0], 4 'ease-in': [0.42, 0.0, 1.00, 1.0], 5 'ease-out': [0.00, 0.0, 0.58, 1.0], 6 'ease-in-out': [0.42, 0.0, 0.58, 1.0] 7}
If you need to scroll multiple containers simultaneously, you can import the scroller factory directly and create multiple instances. (Using the default scrollTo
methods allows for only one scroll action at a time for performance reasons.)
1import {scroller} from 'vue-scrollto/src/scrollTo' 2const firstScrollTo = scroller() 3const secondScrollTo = scroller() 4firstScrollTo('#el1') 5secondScrollTo('#el2')
MIT
No vulnerabilities found.
Reason
all last 30 commits are reviewed through GitHub
Reason
no vulnerabilities detected
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
Reason
license file detected
Details
Reason
tokens are read-only in GitHub workflows
Reason
all dependencies are pinned
Details
Reason
no binaries found in the repo
Reason
0 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 0
Reason
no badge detected
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Reason
project is not fuzzed
Score
Last Scanned on 2022-08-15
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moresvelte-scrollto
Svelte action that listens for click events and scrolls to elements with animation. Inspired by rigor789/vue-scrollto.
svelte-scrollto-element
Svelte action that listens for click events and scrolls to elements with animation. Inspired by rigor789/vue-scrollto.
vue-virtual-scroll-grid
This is a reusable component for Vue 3 that renders a list with a huge number of items (e.g. 1000+ items) as a grid in a performant way.
jquery.scrollto
Lightweight, cross-browser and highly customizable animated scrolling with jQuery