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

@scottjarvis/scrollstory

v1.0.1

Published

A scrolly-telling library, uses requestAnimationFrame, based on google/scrollytell, but simplified a little

Downloads

17

Readme

ScrollStory

A tiny (~770 bytes) JavaScript library for creating animations that synchronize with page scrolling. It uses requestAnimationFrame to check the scroll status and trigger scrollytelling events.

Check out the online demo: https://sc0ttj.github.io/scrollstory/examples/basic-usage.html

npm version Dependency Status devDependencies Status Node version Build Status bundle size Downloads

Before going over the usage and API, let's establish a vocabulary.

Installation

In browsers:

<script src="https://unpkg.com/@scottjarvis/scrollstory"></script>
<script>
  // use it here
</script>

In NodeJS:

Install it:

npm i @scottjarvis/scrollstory

Then import it into your project:

import ScrollStory from "@scottjarvis/scrollstory";

Usage (API)

Just create a ScrollStory object and pass in a config object.

The config contains event handlers and elements. The only two required fields are container (which should select a single DOM element) and scenes (which should be a NodeList or Array of several DOM elements).

Here's an example:

var story = new ScrollStory({
    container: document.querySelector(".container"),
    scenes: document.querySelectorAll(".scene"),
    // Define what happens on "enter", "progress" and "exit" of scenes
    enter: data => console.log(data),
    progress: data => console.log(data),
    exit: data => console.log(data),
});

Note, the data param passed into enter, exit and progress will contain stuff like this:

{ 
  scene: 1,
  element: <scene elem>, 
  progress: 0.809890765659, 
  direction: "down" 
}

To make a useful story, you'll probably want to do something useful in enter, progress and exit callbacks, which are triggered when a scene crosses in or out of the guideline.

For continuous-style scrollytelling, you can provide a progress calback which is triggered every time the progress value changes or the active scene changes.

See examples/basic-usage.html.

Putting your code in the progress handler saves power on mobile devices because it only does work when the scroll position changes.

Custom render loops

Additionally, the ScrollStory object exposes a few methods:

/**
 * Returns the zero-based index of the panel that is currently overlapping
 * the guideline. Returns -1 if no such panel exists.
 */
getActivePanelIndex(): number;

/**
 * Returns a percentage in the range [0, 1] that represents the position of
 * the active panel relative to the guideline. Returns 0 when the top of the
 * panel aligns with the guideline, +1 when the bottom of the panel aligns
 * with the guideline, and -1 if no panel is overlapping the guideline.
 */
getProgressValue(): number;

The above methods provide a way of using the library if you'd like to avoid the event handlers and instead create your own render loop that polls the status of the story.

Issues

Because of its focus on mobile platforms, currently scrollstory does not gracefully handle situations where the container is resized by the user (e.g. if the container expands to fill a browser window). This may be fixed in the future.

Credits

Based on google/scrollytell.

Changelog

v1.0.0

Started with google/scrollytell, then:

  • made more portable: removed internal calls to document.querySelector
    • you must now pass in the elements to the config, not the selectors:
      • config.container (elem) replaces config.containerSelector (string)
      • config.scenes (NodeList) replaces config.panelSelector (string)
  • simplified: removed "chart" stuff, and fullscreenChart stuff:
    • use only "scenes" for defining/dividing scroll content
  • simplified CSS used in examples (see basic-usage.html)
  • simplfied: renamed callbacks available in config:
    • enterHandler() => enter()
    • exitHandler() => exit()
    • progressHandler() => progress()
  • improved the data/object passed to the callbacks, so each receives:
    • { scene, element, progress, direction }
  • removed developer HUD / debug console (just console log d in callbacks instead)

Alternative projects