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

react-floaters

v0.0.1

Published

Apply physics-based motion to components on scroll.

Downloads

2

Readme

React Floaters

A spring-based scroll animation experiment with React.js

This project is the result of experimenting with parallax-like effects. Rather than simply moving two things at different speeds, I wanted to see what happened if the items were given inertia and followed some basic rules of physics.

When you scroll quickly and stop, the items shouldn't just halt instantly, they should overshoot the target and bounce back!

Play with it on Codepen

Note: This is an experimental project. It is untested, and may not work in all browsers. If there is significant interest, I will write a proper release :)


Features

  • Organic, beautiful motion using spring physics
  • Drop-dead simple to use. Simply wrap your components in a Floater and watch 'em float.
  • Efficient - relies exclusively on hardware-accelerated properties, uses requestAnimationFrame when available, etc.
  • Predictable positioning. Unlike parallax, Floaters can be used alongside stationary elements; Floaters animate during scroll transition, but they come to rest in the right place.
  • Configurable. With 3 tweakable settings, a wide range of effects can be applied to Floaters.
  • Tiny! Only 4kb ⚡

Getting Started

Installation:

$ npm i -S react-floaters

Usage:

import { Floater } from 'react-floaters';

const bouncyHeading = () => (
  <Floater>
    <h1>Hello World</h1>
  </Floater>
)

API Documentation

children

| Accepted Types: | Default Value | |---------------------|-------------------| | Array, Object | undefined |

The children passed to Floater are the component(s) or DOM element(s) that will be moved about. Accepts either a single child or an array of children.

stiffness

| Accepted Types: | Accepted Values | Default Value | |---------------------|-------------------|---------------------| | Number | 0 - 1000 | 40 |

Note: I'm not a physicist and this definition is just how it feels to me stiffness is a measure of how elastic the transition is. Higher numbers feel 'looser', and will wobble with less force.

To get a sense of how this value affects the animation, check out this fantastic spring parameter chooser from React Motion.

damping

| Accepted Types: | Accepted Values | Default Value | |---------------------|-------------------|---------------------| | Number | 0 - 200 | 20 |

Note: I'm not a physicist and this definition is just how it feels to me damping is a measure of how much "springiness" the transition is. High numbers feel more like traditional easing, whereas low numbers wobble back and forth a ton.

To get a sense of how this value affects the animation, check out this fantastic spring parameter chooser from React Motion.

smoothing

| Accepted Types: | Accepted Values | Default Value | |---------------------|-------------------|---------------------| | Number | 1 - 100 | 3 |

smoothing affects how 'responsive' the transition is to changes.

A low number means it responds fully to changes in scroll position. As a result, it's very snappy, but can feel jarring when used with a PC mousewheel, where scrollwheels work by jumping up by hard steps.

A high number adds a rolling window of recently-seen scroll positions, to smooth out any jerky scrolling. As a result, it adds a higher sense of inertia, as the motion starts slowly and then races to catch up.

Recommended values are between 5 and 15.


Known Quirks

  • On page load, depending on the items' starting position, they can bounce around a little erratically.

  • Some settings will be really jerky when used with a mousewheel. This is because mousewheels sometimes work in steps: each tick of the wheel instantly jumps by 40-80px. A solution to this is to use the smoothing attribute, but that affects the inertia as well. I may introduce the option to force smooth scrolling, so that it works equally well on all devices.

  • If you only have a few Floaters on the page, you should use will-change: transform on all Floater components to optimize them. Read more about will-change

  • The performance of this module is good, but not great. Right now it runs a continuous event loop. It's pretty fast; the loop typically only takes fractions of a millisecond. That said, there's no reason for it to be running when you aren't scrolling and when none of the items are moving.


The Future

This project was a quick Saturday experiment. I have no idea how useful this is for anybody. If it generates significant interest, I'll do it properly, with tests and contribution policies, etc. Let me know if you find it helpful, or if you have ideas about how to make it more useful!