Svelte Scroller screenshot

Svelte Scroller

Author Avatar Theme by Sveltejs
Updated: 10 Jun 2021
361 Stars

A <Scroller> component for Svelte apps

Overview

The svelte-scroller is a scroller component designed for Svelte apps. It allows for smooth scrolling effects and provides various parameters to customize its behavior. This component can be installed and used in Svelte projects.

Features

  • Slot Composition: Requires two elements, one for the background and one for the foreground, which can be customized using slots.
  • Scrolling Threshold: Defines the vertical position that the foreground must scroll past before the background becomes fixed.
  • Section Activation: Once a section crosses a certain point, it becomes ‘active’.
  • CSS Selector: Allows users to specify the individual sections of the foreground using a CSS selector.
  • Parallax Scrolling: Enables the background to scroll in a way that it reaches the bottom at the same time as the foreground.

Installation

To install the svelte-scroller component, follow these steps:

  1. Include “svelte” in the resolve.mainFields section of your webpack configuration if you’re using webpack with svelte-loader. This ensures that the uncompiled component is imported instead of the compiled version, resulting in better efficiency.
resolve: {
  mainFields: ['svelte', 'browser', 'module', 'main']
}
  1. If you’re using Rollup with rollup-plugin-svelte, this step is not required as the configuration is handled automatically.
  2. Add the svelte-scroller component to your Svelte project.

Summary

The svelte-scroller component is a valuable tool for creating scrolling effects in Svelte apps. Its features such as slot composition, scrolling thresholds, section activation, and parallax scrolling provide flexibility for achieving various scrolling effects. By following the installation guide, users can easily integrate this component into their Svelte projects.