sveltejs/svelte-scroller

Name: svelte-scroller

Owner: Svelte

Description: A component for Svelte apps

Created: 2018-05-02 22:10:02.0

Updated: 2018-05-14 11:11:55.0

Pushed: 2018-05-03 21:35:37.0

Homepage: https://svelte.technology/repl?version=2.4.1&gist=39be370bdc929da668cf205b04a6c822

Size: 13

Language: HTML

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

svelte-scroller (demo)

A scroller component for Svelte apps.

Installation
 add @sveltejs/svelte-scroller
Usage
oller top={0.2} bottom={0.8} bind:index bind:offset bind:progress>
iv slot="background">
<p>
  This is the background content. It will stay fixed
  in place while the foreground scrolls over the top.
</p>

<p>Section {index + 1} is currently active.</p>
div>

iv slot="foreground">
<section>This is the first section.</section>
<section>This is the second section.</section>
<section>This is the third section.</section>
div>
roller>

le>
ction { height: 80vh; }
yle>

ipt>
port Scroller from '@sveltejs/svelte-scroller';

port default {
components: { Scroller }

ript>

You must have one slot="background element and one slot="foreground" element ? see composing with <slot> for more info.

Parameters

The following parameters are available:

| parameter | default | description | |———–|———–|———————————————————————————————————————————————————————————————————————| | top | 0 | The vertical position that the top of the foreground must scroll past before the background becomes fixed, as a proportion of window height | | bottom | 1 | The inverse of top ? once the bottom of the foreground passes this point, the background becomes unfixed | | threshold | 0.5 | Once a section crosses this point, it becomes 'active' | | query | 'section' | A CSS selector that describes the individual sections of your foreground | | parallax | false | If true, the background will scroll such that the bottom edge reaches the bottom at the same time as the foreground. This effect can be unpleasant for people with high motion sensitivity, so use it advisedly |

index, offset, progress and count

By binding to these properties, you can track the user's behaviour:

You can rename them with e.g. bind:index=i.

Configuring webpack

If you're using webpack with svelte-loader, make sure that you add "svelte" to resolve.mainFields in your webpack config. This ensures that webpack imports the uncompiled component (src/index.html) rather than the compiled version (index.mjs) ? this is more efficient.

If you're using Rollup with rollup-plugin-svelte, this will happen automatically.

Using without Svelte

You can also use <Scroller> in a non-Svelte app:

rt Scroller from '@sveltejs/svelte-scroller';

t background = document.createElement('div');
ground.innerHTML = someHTML;

t foreground = document.createElement('div');
ground.innerHTML = someMoreHTML;

t scroller = new Scroller({
rget: document.querySelector('#scroller-target'),
ta: { top: 0.1, bottom: 0.9 },
ots: { background, foreground }

License

LIL


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.