New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svelte-scrolling

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-scrolling

Scroll to given elements with smooth animation

  • 1.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
472
increased by11.06%
Maintainers
0
Weekly downloads
 
Created
Source

Svelte Scrolling

npm license

Scroll to given elements with smooth animation.

Install

yarn add svelte-scrolling

Usage

<script>
  import { scrollTo, scrollRef, scrollTop } from 'svelte-scrolling'
</script>

<nav>
  <a use:scrollTo={'home'}>Home</a>
  <a use:scrollTo={'about'}>About</a>
  <a use:scrollTo={{ ref: 'blog', duration: 1000 }}>Blog</a>
</nav>

<section use:scrollRef={'home'}></section>
<section id="about"></section>
<section use:scrollRef={'blog'}></section>

<ScrollTop>
  <button on:click={() => scrollTop()}>Go to top</button>
</ScrollTop>

Actions

scrollTo={reference | options}

This action listens for click (touchstart) events and scrolls to elements with smooth animation. The element to scroll to must be referenced using the scrollRef action or id.

Accepts as parameter only the element reference or all global options:

  • ref: Element reference.

To set the global options, the ref property is required

scrollRef={reference}

This action adds a reference to the elements that scrollTo should scroll.

Accepts as parameter a string with the name to reference the element

Functions

scrollTop(options?)

Scroll to the top of the page

scrollBottom(options?)

Scroll to the end of the page

scrollLeft(options?)

Scroll to the end of left the page

scrollRight(options?)

Scroll to the end of right the page

scrollElement(reference, options?)

Scroll to element with smooth animation.

scrollPosition(position, options?)

Scroll to a position on the page

API

Global Options

PropertyDefaultDescription
duration500Duration (in milliseconds) of the animation.
offset0Offset that should be applied when scrolling.
easingcubicInOutEasing function to be used when animating. Use any easing from svelte/easing or a custom easing function.
passivefalseA boolean value that, if true, indicates that the function specified by listener will never call preventDefault().
onStartnoopA callback function that should be called when scrolling has started. Receives the element, offset, duration and endPosition as a parameter.
onDonenoopA callback function that should be called when scrolling has started. Receives the element, offset, duration and endPosition as a parameter.

Override global options

<script>
  import { setGlobalOptions } from 'svelte-scrolling'

  setGlobalOptions({
    duration: 800
  })
</script>

License

MIT

Copyright (c) 2021-present, Valmisson Grizorte

Keywords

FAQs

Package last updated on 03 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc