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 🙏

© 2026 – Pkg Stats / Ryan Hefner

data-scroll-animation

v2.0.0

Published

Animates element properties on scroll, declared with data attributes

Readme

scroll-based HTMLElement property management

Installation

npm install data-scroll-animation

Usage

data-scroll-parent attribute

Specifies the start and end point of nested animation

data-scroll-top

Defines top offset in px

data-scroll-bottom

Defines bottom offset in px

The animation begins at start - topOffset and ends at end + bottomOffset

┌-------------------> topOffset     = frame 0
|
|
╔═════════════════╗-> start
║                 ║
║      PARENT     ║
║                 ║
╚═════════════════╝-> end
|
|
└-------------------> bottomOffset  = frame 1

data-scroll-(property)-(frame)="(value)"

Sets property of the attribute owner element to value at specified frame

property have format [property.]*property, so style.width works as well customProperty

value is linearly interpolated between frames, unless an easing is set special frames are "before" and "after"

Before the first frame and after the last one the value of the nearest frame is kept

data-scroll-(property)-extrapolate

Extends the first and the last interpolation segments of property up to frame 0 and frame 1 instead of keeping the nearest value

The attribute value is ignored. It needs at least two numeric frames and is ignored when the values can't be interpolated

<div
    data-scroll-style.top-0.2="10px"
    data-scroll-style.top-0.8="40px"
    data-scroll-style.top-extrapolate
></div>
<!-- top is 0px at frame 0, 5px at 0.1, 45px at 0.9 and 50px at 1 -->

data-scroll-(property)-easing="(easing)"

Applies easing to every interpolation segment of property, like animation-timing-function does between CSS keyframes

easing is one of:

  • linear
  • a function of easings.net in kebab-case: ease-(in|out|in-out)-(sine|quad|cubic|quart|quint|expo|circ|back|elastic|bounce), for example ease-in-out-cubic or ease-out-bounce
  • the CSS functions cubic-bezier(x1, y1, x2, y2) and steps(count, position)

An invalid value is ignored and the segments stay linear

The segments extended by -extrapolate stay linear

<div
    data-scroll-style.top-0="0px"
    data-scroll-style.top-0.5="100px"
    data-scroll-style.top-1="0px"
    data-scroll-style.top-easing="ease-in-out-cubic"
></div>
<!-- top eases in and out from 0px to 100px and back -->

data-scroll-(method)()

Calls method every frame with frame number as first and only argument method(frame: number): number

import ScrollAnimation from "data-scroll-animation";

ScrollAnimation.add(document.body); // adds all animation in the document
ScrollAnimation.add(document.querySelector("#animation")) // adds only the #animation element

ScrollAnimation.remove(document.querySelector("#element")) // removes only the #element element

Render method

By default animations are rendered only when something can have moved a parent. setMethod switches to rendering on every animation frame, even when the page is still:

ScrollAnimation.setMethod(ScrollAnimation.METHOD.ANIMATION_FRAME); // render every frame
ScrollAnimation.setMethod(ScrollAnimation.METHOD.EVENTS); // render on events (default)

With METHOD.EVENTS a render is scheduled on the next frame after:

  • scroll of the page or of any inner scrollable container;
  • resize of the window;
  • resize of a parent or of the whole document (for example content above a parent that grows or shrinks).

A parent that moves without any of these is not detected: for example inside a fixed-height scrollable container, when an element above the parent changes height or the margin-top of the parent changes, or in the page when an element above the parent grows and another one shrinks by the same amount. In these cases call requestRender after the change:

ScrollAnimation.requestRender(); // schedules a render on the next frame, does nothing with METHOD.ANIMATION_FRAME

Smoothness and browser limitations

Browsers scroll on a separate thread (the compositor), while animations are rendered by JavaScript on the main thread. Chromium and Firefox keep the two in sync as long as the page renders on every frame, so with both render methods the animations follow the scroll without lag.

Elements whose animation compensates the scroll are the most sensitive to a missed frame: for example a top that grows while scrolling to keep an element still, or a switch between position: absolute and fixed. When the page misses a frame the compositor has already scrolled the content but the element is still in the previous position, so it visibly jumps back and forth.

This happens with Firefox on Linux under X11 (observed with Firefox 158 and an integrated Intel GPU), even if the render takes less than 2ms: the page often misses the vertical sync and stays one or two frames behind the scroll. It is not specific to this library: it happens with any scroll-linked effect made in JavaScript, and in Firefox also with CSS scroll-driven animations, because there they still run on the main thread. The same pages are smooth on Chromium and on Firefox for Android. See the Firefox bug about scroll-linked effects.

To reduce the problem:

  • make elements that stay still while the content scrolls with position: sticky, which the compositor moves together with the scroll, and use the animations for the other properties (colors, sizes, opacity, movements of the element itself), where a late frame is not noticeable;
  • on Linux a Wayland session should give a more regular frame timing than X11; check that Firefox runs on Wayland natively in about:support (Window Protocol must be wayland, not xwayland).

Development

npm run build

Builds dist/ (UMD, ES module and type declarations)

npm run dev

Rebuilds test/scripts/main.js on every change and serves the test page at http://localhost:8080

npm run build:test

Builds test/scripts/main.js once