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

@apatheticwes/stickynav

v0.5.8

Published

A simple navigation bar that efficiently attaches / detaches to the top of the viewport upon scrolling

Downloads

5

Readme

Sticky Nav

NPM Version License

A package of "Sticky Navigation" utilities

Introduction

A collection of 3 mini-utilities: a "sticky" Class to affix elements to the top of the viewport when scrolled, a function to smoothly scroll the page to any anchor, and a Class that auto-generates an in-page navigation from data-attribues in the DOM.

Scroll and Sticky may be used individually, but when used in tandem via StickyNav the result is an automatically created navigation menu that sticks to the top of the viewport, with nav-items that smoothly scroll to corresponding anchors in the page.

Installation

If you're oldskool, you can download the pre-built version to quickly mess around. Otherwise:

npm i @apatheticwes/stickynav -D

ES6

import { Sticky, Scroll, StickyNav } from 'stickynav';

CommonJS

var sticky = require('stickynav').Sticky;
var stickynav = require('stickynav').StickyNav;
var scroll = require('stickynav').Scroll;

Recipes

Create an auto-generated sticky navigation from in-page DOM elements:

<!-- this will become a sticky navigation, populated with nav items that initiate smooth scrolling when clicked -->
<ul id="sticky"></ul> 

...

<main>
  <section data-nav="Introduction">
  <section data-nav="Overview">
  <section data-nav="Summary">
</main>
new stickyNav({
  nav: '#sticky'
});

Or, just create a sticky element. This one is bounded by its parent (meaning it will unstick along with the bottom edge of its parent), and will become sticky 80px from the top of the viewport:

new Sticky('#sticky', {
  boundedBy: true,
  offset: 80
}

Smoothly scroll to a particular page section or anchor:

const intro = document.querySelector('#intro');

scrollPage(intro);

Options

Sticky

| name | type | default | description | | ---------------- | -------------------- | ------- | ----------- | | element | HTMLElement | | The element to sticky-ify (required). | | option.boundedBy | boolean, HTMLElement | | "true" to use the parent node, or a custom bounding element for the sticky element. This affects where / when the sticky will attach and detach | | option.offset | number | 0 | An offset from the top at which to toggle "stickiness" |

Scroll

| name | type | default | description | | ---------- | ----------- | ------- | -------------------------------------------- | | to | HTMLElement | | The DOM node to scroll to (required) | | offset | number | 0 | A scrolling offset | | callback | function | | Callback function when scrolling is complete |

StickyNav

| name | type | default | description | | ---------------- | -------------------- | -------- | -------------------------------------------- | | option.nav | HTMLElement | | The DOM node to generate the nav into (required)| | option.sections | string, HTMLElement | data-nav | A querySelector, or the elements themselves, to be used when generating the menu items in the navigation | | option.boundedBy | boolean, HTMLElement | false | "true" to use the parent node, or a custom bounding element for the sticky element. This affects where / when the sticky will attach and detach | | option.offset | number | 0 | The scroll / sticky offset |

Examples

There is a demo is available. Alternatively, after cloning the repo, try:

npm i
npm start

A server will spin up at http://localhost:8080, where you may play with the various examples.

Support

  • IE8+
  • Safari / Chrome
  • Firefox
  • iOS
  • Android

License

MIT