npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-scrollto

v0.2.0

Published

Svelte action that listens for click events and scrolls to elements with animation. Inspired by rigor789/vue-scrollto.

Downloads

5,045

Readme

Svelte-scrollto

Animating vertical and horizontal scrolling

Install

npm install --save-dev svelte-scrollto
# or
yarn add -D svelte-scrollto

Usage

<script>
  import * as animateScroll from "svelte-scrollto";
</script>

<a on:click={() => animateScroll.scrollToBottom()}> Scroll to bottom </a>
<a on:click={() => animateScroll.scrollToTop()}> Scroll to top </a>
<a on:click={() => animateScroll.scrollTo({element: 'scroll-to-element-selector'})}> Scroll to element </a>
<a on:click={() => animateScroll.scrollTo({element: 'scroll-to-element-selector', offset: 200})}> Scroll to below element 200px </a>
<a on:click={() => animateScroll.scrollTo({element: 'scroll-to-element-selector', duration: 2000})}> Scroll to element over 2000ms </a>

Using as a action

<script>
  import { scrollto } from "svelte-scrollto";
</script>
<!-- Parameter is element selector or options -->
<a use:scrollto={'#scroll-element'}> Scroll to element </a>

API

Global Options

| 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:

import * as animateScroll from "svelte-scrollto";

animateScroll.setGlobalOptions({
	offset: 200,
	onStart: (element, offset) => {
		if(element) {
			console.log("Start scrolling to element:", element);
		} else if(offset) {
			console.log("Start scrolling to page offset: (${offset.x}, ${offset.y})");
		}
	}
})

Functions

scrollTo(options)

Accepts all global options and:

  • element: The element you want scroll to
  • x: The offset we want to scrolling on the x axis
  • y: The offset we want to scrolling on the y axis

scrollToTop(options)

Shortcut of use scrollTo with x equal to 0.

scrollToBottom(options)

Shortcut of use scrollTo with x equal to containerHeight

Actions

Svelte action that listens for click (touchstart) events and scrolls to elements with animation.

  • scrollto

  • scrolltotop

  • scrolltobottom

Troubleshooting

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.