
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
react-floaters
Advanced tools
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!
Installation:
$ npm i -S react-floaters
Usage:
import { Floater } from 'react-floaters';
const bouncyHeading = () => (
<Floater>
<h1>Hello World</h1>
</Floater>
)
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.
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.
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!
FAQs
Apply physics-based motion to components on scroll.
The npm package react-floaters receives a total of 1 weekly downloads. As such, react-floaters popularity was classified as not popular.
We found that react-floaters demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.