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

parallax-lit-hero

v1.0.4

Published

The `ParallaxHero` is a custom Web Component built using [Lit](https://lit.dev/). It encapsulates a dynamic, mouse-tracking background parallax effect originally created (by me) in the NavigoLearn repository (in React), making it reusable across any web f

Readme

ParallaxHero Web Component

The ParallaxHero is a custom Web Component built using Lit. It encapsulates a dynamic, mouse-tracking background parallax effect originally created (by me) in the NavigoLearn repository (in React), making it reusable across any web framework (or vanilla HTML).

<parallax-hero></parallax-hero>

<!-- Overlay some text to demonstrate the background effect -->
<div style="position: relative; z-index: 10; display: flex; align-items: center; justify-content: center; height: 100vh; pointer-events: none;">
  <h1 style="font-family: sans-serif; color: #1e293b; font-size: 3rem;">Move your mouse!</h1>
</div>

Installation & Setup

  1. Make sure you have the Lit library installed in your project:

    npm install lit
  2. If you are importing this specifically into a React application, you will also need the @lit/react wrapper to seamlessly pass events and props:

    npm install @lit/react

How It Works

The component uses an internal requestAnimationFrame loop that runs independently of your application's main framework render cycle. It performs two main animations:

  1. Floating Nodes: A vertical oscillating animation (using a precomputed sine wave table for performance) is applied to individual background rectangles.
  2. Mouse Parallax: The component listens to the global mousemove event. It tracks the distance of the mouse relative to the screen center and applies a linear interpolation (lerp) to gently shift the entire <g> (group) of rectangles based on the cursor's position.

Because it inherits from LitElement, it leverages an efficient Shadow DOM update mechanism, selectively re-rendering only the attributes (like transforms and coordinates) that change on every frame.

How to Utilize It

In Vanilla HTML or other Frameworks

Simply import the definition script, and use the custom element tag <parallax-hero> anywhere in your markup:

<script type="module" src="./path/to/ParallaxHero.ts"></script>

<body>
  <!-- The component has absolute positioning and takes up 100vw/100vh by default -->
  <parallax-hero></parallax-hero>
  
  <div style="position: relative; z-index: 10;">
    <h1>My Website Content</h1>
  </div>
</body>

In a React Application

React requires a wrapper to perfectly interoperate with Custom Elements (especially regarding synthetic events).

At the bottom of ParallaxHero.ts, you can uncomment or use the @lit/react wrapper:

import React from 'react';
import { createComponent } from '@lit/react';
import { ParallaxHero } from './ParallaxHero';

export const ParallaxHeroReact = createComponent({
  tagName: 'parallax-hero',
  elementClass: ParallaxHero,
  react: React,
});

Then, import the wrapped component into your React tree:

import { ParallaxHeroReact } from './path/to/ParallaxHero';

function App() {
  return (
    <div style={{ position: 'relative' }}>
      <ParallaxHeroReact />
      <main style={{ position: 'relative', zIndex: 10 }}>
        <h1>Welcome to my React App</h1>
      </main>
    </div>
  );
}

export default App;

How to Customize

You can customize the appearance and behavior directly within ParallaxHero.ts:

1. Modifying the Shapes and Colors

Inside the render() method, look for the mapped nodes:

<rect
  x="${node.targetX}"
  y="${node.currentY}"
  width="96"  /* Change width */
  height="32" /* Change height */
  rx="4"      /* Border radius */
  ry="4"      /* Border radius */
  class="parallax-node"
></rect>

To change the color, update the static CSS styles defined at the top of the class:

rect.parallax-node {
  fill: white;          /* Change fill color */
  stroke: #94a3b8;      /* Change border color */
  stroke-width: 2px;
}

2. Changing the Background Gradients

The SVG uses <radialGradient> and <linearGradient> applied to a mask to create a fade-out effect around the edges. To change these, edit the <defs> and <mask id="mask"> section inside the render() function. You can also change the core background color within the :host CSS block (background-color: white;).

3. Adjusting Node Generation & Density

You can control how many nodes are generated and how far apart they are by tweaking the constants at the top of ParallaxHero.ts:

const SPACING_X = 250;      // Distance between nodes horizontally
const SPACING_Y = 300;      // Distance between nodes vertically
const RANDOM_OFFSET = 0.7;  // How much randomness in their placement

4. Adjusting Animation Speeds

  • Floating intensity: In startAnimation(), change the floatingEffect variable (currently 25).
  • Mouse tracking speed: Modify the denominator in the distance calculations:
    // Increase 12 to make the mouse tracking effect more subtle, or decrease to make it more pronounced.
    this.viewCoords = {
      x: lerp(this.viewCoords.x, DISTANCE_X / 12, 0.2),
      y: lerp(this.viewCoords.y, DISTANCE_Y / 12, 0.2),
    };