Gathering detailed insights and metrics for svelte-scrollto-element
Gathering detailed insights and metrics for svelte-scrollto-element
Gathering detailed insights and metrics for svelte-scrollto-element
Gathering detailed insights and metrics for svelte-scrollto-element
Scroll to element with smooth animation. Lightweight library for Svelte. No dependencies! Pure Svelte.
npm install svelte-scrollto-element
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
17 Stars
28 Commits
5 Forks
3 Watching
4 Branches
3 Contributors
Updated on 18 Aug 2024
TypeScript (94.72%)
JavaScript (4.37%)
Shell (0.91%)
Cumulative downloads
Total Downloads
Last day
109.1%
23
Compared to previous day
Last week
59.4%
110
Compared to previous week
Last month
-15.3%
355
Compared to previous month
Last year
-36.9%
5,585
Compared to previous year
1
Animating vertical and horizontal scrolling (for Svelte)
- TypeScript / JavaScript
- Useful options
- Compatible with
SvelteKit
,SSR
andadapter-static
1npm install svelte-scrollto-element --save 2# yarn add svelte-scrollto-element
1<script> 2 import { animateScroll } from 'svelte-scrollto-element'; 3</script> 4 5<a on:click={() => animateScroll.scrollToBottom()}> Scroll to bottom </a> 6<a on:click={() => animateScroll.scrollToTop()}> Scroll to top </a> 7<a on:click={() => animateScroll.scrollTo({element: '#my-anchor'})}> Scroll to element with id="my-anchor" </a> 8<a on:click={() => animateScroll.scrollTo({element: '.my-element-class', offset: 200})}> Scroll to below element 200px </a> 9<a on:click={() => animateScroll.scrollTo({element: 'footer', duration: 2000})}> Scroll to footer element over 2000ms </a>
1<script> 2 import { scrollto } from 'svelte-scrollto-element'; 3</script> 4<!-- Parameter is element selector or options --> 5<a use:scrollto={'#scroll-element'}> Scroll to element </a>
Option | Required | Default value | Description |
---|---|---|---|
container | ✔ | "body" | Scroll container |
duration | ✔ | 500 | The duration (in milliseconds) of the scrolling animation. |
delay | 0 | ||
offset | 0 | The offset that should be applied when scrolling. This option accepts a callback function | |
easing | cubicInOut | The easing function to be used when animating. Can pass any easing from svelte/easing or pass custom easing function. | |
onStart | noop | A callback function that should be called when scrolling has started. Receives the target element and page offset as a parameter. | |
onDone | noop | A callback function that should be called when scrolling has ended. Receives the target element and page offset as a parameter. | |
onAborting | noop | A callback function that should be called when scrolling has been aborted by the user (user scrolled, clicked etc.). Receives the target element and page offset as parameters. | |
scrollX | false | Whether or not we want scrolling on the x axis | |
scrollY | true | Whether or not we want scrolling on the y axis |
Override global options:
1import { animateScroll } from 'svelte-scrollto-element'; 2 3animateScroll.setGlobalOptions({ 4 offset: 200, 5 onStart: (element, offset) => { 6 if (element) { 7 console.log('Start scrolling to element:', element); 8 } else if (offset) { 9 console.log('Start scrolling to page offset: (${offset.x}, ${offset.y})'); 10 } 11 } 12});
scrollTo(options)
Accepts all global options and:
element
: The element you want scroll tox
: The offset we want to scrolling on the x axisy
: The offset we want to scrolling on the y axisscrollToTop(options)
Shortcut of use scrollTo with x
equal to 0
.
scrollToBottom(options)
Shortcut of use scrollTo with x
equal to containerHeight
Svelte action that listens for click
(touchstart
) events and scrolls to elements with animation.
scrollto
scrolltotop
scrolltobottom
If you want to use Lazy and want to scroll to elements, you need to give your lazy components (images, v.v..) fixed dimensions, so the browser known the size of the not loaded elements before scrolling.
Initially forked from langbamit/svelte-scrollto which is archived now. Uses some of its code and functionality!
I DO NOT STORE ANY DATA. PERIOD.
I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.
That's why, with this library, what happens on your device stays on your device till disappear.
Initially forked from langbamit/svelte-scrollto which is archived now.
Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)
All contents are licensed under the MIT license.
No vulnerabilities found.
No security vulnerabilities found.