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

@chayson/stick-it

v1.1.0

Published

A simple JS module to apply sticky header behavior.

Downloads

128

Readme

StickIt

StickIt is a modern, customizable sticky header plugin that allows you to "stick" elements to the top of the viewport on demand. It is a modernized and enhanced version of the original Headhesive.js by Mark Goodyear, updated and maintained by Chayson Media Group.

StickIt supports configurable offsets, numeric or element-based triggers, and includes modern development features like source maps and modular code.


Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Configuration
  5. Examples
  6. Development
  7. Credits
  8. License

Features

  • On-Demand Sticky Headers: Stick any element to the top of the page when you scroll past a defined threshold.
  • Configurable Offsets: Trigger sticky behavior using either:
    • A numeric offset (in pixels).
    • An existing element on the page.
  • Modular Codebase: Written in ES6 modules for modern JavaScript development.
  • Production Ready: Minified builds (stick-it.min.js) with source maps for debugging.
  • Customizable: Fully customizable CSS classes and lifecycle callbacks.
  • Lightweight: No external dependencies.

Installation

You can install StickIt via NPM:

npm install @chayson/stick-it

Alternatively, include the pre-built UMD version via a <script> tag:

<script src="dist/stick-it.min.js"></script>

Usage

Including StickIt in Your Project

1. Using ES Modules (Recommended)

If you are using a bundler like Rollup, Webpack, or Vite, you can import StickIt as an ES module:

import StickIt from './dist/stick-it.min.js';

2. Using UMD Build

Include StickIt in your project using a <script> tag. This makes StickIt available globally.

<script src="dist/stick-it.min.js"></script>
<script>
  const stickyHeader = new StickIt('.my-header', {
    offset: 200,
    onStick: () => console.log('Header stuck!'),
    onUnstick: () => console.log('Header unstuck!')
  });
</script>

Configuration

StickIt accepts an object with customizable options:

| Option | Type | Default | Description | |------------------|---------------------|------------------------|-----------------------------------------------------------------------------| | offset | number / string| 300 | Numeric scroll offset (in px) or a CSS selector for an element. | | offsetSide | string | 'top' | Determines which side ('top' or 'bottom') is used for the offset. | | classes | object | {} | Custom CSS classes for the sticky element. See below for class options. | | throttle | number | 250 | Delay in ms for throttling scroll and resize events. | | onInit | function | () => {} | Callback when StickIt is initialized. | | onStick | function | () => {} | Callback when the element becomes sticky. | | onUnstick | function | () => {} | Callback when the element is unstuck. | | onDestroy | function | () => {} | Callback when StickIt is destroyed. |

Default Classes

StickIt applies the following CSS classes:

| Class | Description | |----------------------|-----------------------------------------------------| | clone | Applied to the cloned sticky element. | | stick | Applied when the element becomes sticky. | | unstick | Applied when the element is no longer sticky. |


Example: Basic Usage

<!DOCTYPE html>
<html lang="en">
<head>
  <title>StickIt Demo</title>
  <script src="dist/stick-it.min.js"></script>
</head>
<body>
  <header class="my-header">My Sticky Header</header>
  <div style="height: 1500px;">Scroll down to see it stick!</div>

  <script>
    const stickyHeader = new StickIt('.my-header', {
      offset: 100,
      onStick: () => console.log('Header is now sticky!'),
      onUnstick: () => console.log('Header is unstuck.')
    });
  </script>
</body>
</html>

Development

Clone the repository and install dependencies:

git clone https://github.com/chayson/stick-it.git
cd stick-it
npm install

Build the Project

To bundle the project with Rollup, run:

npm run build

The output files will be available in the dist/ folder:

  • stick-it.js - Unminified UMD build.
  • stick-it.min.js - Minified UMD build with source maps.

Credits


License

This project is licensed under the MIT License. See the LICENSE file for details.