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

@parallaxx/toolkit

v0.0.17

Published

Framework-agnostic toolkit for implementing smooth parallax and fade effects using the native ScrollTimeline API. Zero dependencies, maximum performance.

Downloads

402

Readme

ParallaxX Toolkit

A lightweight, framework-agnostic toolkit for implementing smooth parallax and fade effects that leverage the native ScrollTimeline API.

✅ Minuscule footprint (5kb)
✅ Easy to use presets
✅ Maximum performance

Installation

Install the package via npm:

npm i @parallaxx/toolkit

Getting Started

Import the Toolkit

// Import the ParallaxX class and optional preset enums
import { ParallaxX, TranslatePreset, OpacityPreset } from "@parallaxx/toolkit";
// Import the CSS
import "@parallaxx/toolkit/dist/parallaxx.css";

Initialize

Initialize the ParallaxX class in your application. If you're using React/Next.js, initialize it inside useLayoutEffect:

useLayoutEffect(() => {
  new ParallaxX();
}, []);

For other frameworks or vanilla JavaScript, initialize the class after the DOM is ready.

Add Data Attributes

Add data attributes to the elements you want to animate. ParallaxX finds elements with 'data-pxx-translate' and 'data-pxx-opacity' attributes.

<div
  data-pxx-translate={TranslatePreset.FAST}
  data-pxx-opacity={OpacityPreset.FADE_IN}
></div>

Presets

The toolkit provides several presets for convenience. The three values represent the enter, middle (center of the viewport), and exit values of the animation.

enum TranslatePreset {
  SLOWER = "50%,0%,-50%",
  SLOW = "100%,0%,-100%",
  FAST = "200%,0%,-200%",
  FASTER = "300%,0%,-300%",
}

enum OpacityPreset {
  FADE_IN = "0,1,1",
  FADE_IN_OUT = "0,1,0",
  HALF_FADE_IN = "0.5,1,1",
  HALF_FADE_IN_OUT = "0.5,1,0.5",
}
<div
  data-pxx-translate={TranslatePreset.SLOWER}
  data-pxx-opacity={OpacityPreset.FADE_IN_OUT}
></div>

View the website

Custom Values

For greater flexibility you can provide custom values. These are comma-separated strings representing the enter, middle, and exit values.

Translate values can be anything that CSS translate3d supports. Opacity values should range between 0 and 1.

// Translate the element from 120px to -120px as it moves through the view.
// Fade the element from 0.2 opacity to 1.0 as it reaches the center of the view.
<div data-pxx-translate="120px,0,-120px" data-pxx-opacity="0.2,1.0,1.0"></div>

// Translate the element from 10vh to -20vh as it moves through the view. Aligning in the center (0)
// Fade the element from 0 opacity to 1.0 as it reaches the center of the view, and then back out to 0.4 as it exits.
<div data-pxx-translate="10vh,0,-20vh" data-pxx-opacity="0,1,0.4"></div>

Random Values

Values can be randomly generated too - which is useful for sets of mapped elements. The format is "random(min|max)"

// The following will result in a random exit value between -10px and -200px
<div data-pxx-translate="0,0,random(-10|-200)"

Adjusting Range

The range controls when the animation timeline starts and ends. With cover (default) the timeline begins as the element starts to enter the view, and ends when it has completely left it. With contain the timeline begins after the entire element has entered the view, and ends as it starts to leave.

You can customise these values to fine-tune the start and ending using different values.

More Info

export enum RangePreset {
  COVER = "cover 0% cover 100%", // Default
  CONTAIN = "contain 0% contain 100%",
}

How It Works

By utilizing native browser capabilities and minimizing reliance on JavaScript, ParallaxX outperforms animation frameworks that compute animations on the main thread.

Browser Support

If window.ScrollTimeline() is not supported, a polyfill is loaded.

License

This project is licensed under the MIT License.