Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 11, 2021. It is now read-only.

Animating vertical and horizontal scrolling. Inspired by rigor789/vue-scrollto and uses some of its code and functionality!!

NotificationsYou must be signed in to change notification settings

utherpally/svelte-scrollto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Animating vertical and horizontal scrolling

Install

npm install --save-dev svelte-scrollto# oryarn add -D svelte-scrollto

Usage

<script>import*asanimateScrollfrom"svelte-scrollto";</script><aon:click={() => animateScroll.scrollToBottom()}> Scroll to bottom</a><aon:click={() => animateScroll.scrollToTop()}> Scroll to top</a><aon:click={() => animateScroll.scrollTo({element: 'scroll-to-element-selector'})}> Scroll to element</a><aon:click={() => animateScroll.scrollTo({element: 'scroll-to-element-selector', offset: 200})}> Scroll to below element 200px</a><aon: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 --><ause:scrollto={'#scroll-element'}> Scroll to element</a>

API

Global Options

OptionRequiredDefault valueDescription
container"body"Scroll container
duration500The duration (in milliseconds) of the scrolling animation.
delay0
offset0The offset that should be applied when scrolling. This option accepts a callback function
easingcubicInOutThe easing function to be used when animating. Can pass any easing fromsvelte/easing or pass custom easing function.
onStartnoopA callback function that should be called when scrolling has started. Receives the target element and page offset as a parameter.
onDonenoopA callback function that should be called when scrolling has ended. Receives the target element and page offset as a parameter.
onAbortingnoopA 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.
scrollXfalseWhether or not we want scrolling on thex axis
scrollYtrueWhether or not we want scrolling on they axis

Override global options:

import*asanimateScrollfrom"svelte-scrollto";animateScroll.setGlobalOptions({offset:200,onStart:(element,offset)=>{if(element){console.log("Start scrolling to element:",element);}elseif(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 withx equal to0.

scrollToBottom(options)

Shortcut of use scrollTo withx equal tocontainerHeight

Actions

Svelte action that listens forclick (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.

About

Animating vertical and horizontal scrolling. Inspired by rigor789/vue-scrollto and uses some of its code and functionality!!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp