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

parallaxis

v1.2.1

Published

A tiny parallax library that updates styles on scroll

Downloads

43

Readme

Parallaxis

A tiny parallax library that updates styles on scroll

  • Plain old vanilla JS
  • Just 1.8kb gzipped

Be careful out there

Parallax works by listening to every scroll event. Now, that's not great, as it can really mess performance up.

Parallaxis allows only a few of the best performing element styles to be updated on scroll.

  • opacity
  • translateX
  • translateY
  • scale

Still, overuse may kill performance. Especially on low-end devices.

Examples

Codepen

Alternatively, take a look in /examples.

Installation

npm install parallaxis

Usage

<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
  data-opacity-start="1"
  data-opacity-end="0"
>
  Hello world
</h1>
import parallaxis from 'parallaxis'
parallaxis()

The above example translates to:

  • When window.scrollY equals 0 then the opacity of the h1 will be 1.
  • When window.scrollY equals 200, or more, then the opacity of the h1 will be 0.
  • When window.scrollY is somewhere between 0 and 200 then the opacity of the h1 will be somewhere between 0 and 1.

Options

The parallaxis function can take an object, that may include the following properties.

className

The class name that Parallaxis uses to locate elements. Defaults to js-parallaxis.

parallaxis({ className: 'my-special-class' })

Data attributes

Parallaxis uses element data attributes for configuration.

Required

start

This is the window.scrollY position that will be the element's update start point.

<h1
  class="js-parallaxis"
  data-start="0"
>
  Hello world
</h1>

end

This is the window.scrollY position that will be the element's update end point.

<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
>
  Hello world
</h1>

Optional

opacity

Defining data-opacity-start and data-opacity-end will result in opacity style updates.

start
<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
  data-opacity-start="1"
  data-opacity-end="0"
>
  Hello world
</h1>

translateX

Defining data-translatex-start and data-translatex-end will result in transform: translateX() style updates.

<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
  data-translatex-start="0"
  data-translatex-end="200"
>
  Hello world
</h1>

translateY

Defining data-translatey-start and data-translatey-end will result in transform: translateY() style updates.

<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
  data-translatey-start="0"
  data-translatey-end="200"
>
  Hello world
</h1>

scale

Defining data-scale-start and data-scale-end will result in transform: scale() style updates.

<h1
  class="js-parallaxis"
  data-start="0"
  data-end="200"
  data-scale-start="1"
  data-scale-end="4"
>
  Hello world
</h1>

relative

If data-relative is set to true, the data-start and data-end attributes will be relative to the element, rather than the window.

<h1
  class="js-parallaxis"
  data-relative="true"
  data-start="-200"
  data-end="0"
  data-opacity-start="0"
  data-opacity-end="1"
>
  Hello world
</h1>

Browser support

Parallaxis is packaged with Babel, and makes use of Array.from. If you want Parallaxis to work on browsers that don't support this method (e.g. IE11), then you will need to polyfill Array.from before calling parallaxis.