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

@yuanqing/sticky

v0.1.0

Published

Sticky items in a scrollable DOM element.

Downloads

3

Readme

sticky.js npm Version Build Status

Sticky items in a scrollable DOM element.

Features

  • Define custom selectors for the scrollable element, the items to make sticky, and the element to hold the “stuck” items
  • Zero dependencies; 1.5 KB minified or 0.7 KB minified and gzipped

Usage

Editable demo

<!DOCTYPE html>
<html>
  <head>
    <title>sticky</title>
    <meta charset="utf-8">
    <style>
      body, p {margin: 0; }
      .sticky {margin: 0 auto; width: 300px; }
      .sticky__content {height: 300px; }
      .sticky__item {background: yellow; }
    </style>
  </head>
  <body>
    <div class="sticky">
      <div class="sticky__stuck"></div>
      <div class="sticky__content">
        <p>Iuvaret intellegat nec at, duo illud conceptam te. Eos habeo omnium principes ne. Cu cum malis ludus equidem, mei nibh nobis ponderum ne, ei mea civibus adipisci. Clita invidunt definitiones duo in, est alii omnes gloriatur te. Mea utroque disputando an. Ne vidit euripidis omittantur per, sea ne iusto saperet, eu equidem maiorum denique vim. Sapientem abhorreant in eam, per ut nonumes accusata scribentur. Pro ea periculis posidonium, duo diceret constituam ea, consul putent cu nec.</p>
        <div class="sticky__item">Ius et aeque adversarium concludaturque eripuit denique et nam, ea mei impetus nominati.</div>
        <!-- ... -->
      </div>
    </div>
    <script src="path/to/sticky.min.js"></script>
    <script>
      var elem = document.querySelector('.sticky');
      var opts = {
        contentSelector: '.sticky__content',
        itemSelector: '.sticky__item',
        stuckSelector: '.sticky__stuck'
      };
      sticky(elem, opts);
    </script>
  </body>
</html>

In the browser, the sticky function is a global variable. In Node, do:

var sticky = require('@yuanqing/sticky');

var s = sticky(elem, opts)

  • elem — A DOM element.

  • opts — An object literal:

    Key | Description | Default :--|:--|:-- contentSelector | Selector for the scrollable element | .sticky__content itemSelector | Selector for items we want to make sticky | .sticky__item stuckSelector | Selector for the element to hold the “stuck” items | .sticky__stuck

s.init()

Re-initialises the component, ie. recomputes the items we want to make sticky. This is uesful if any changes were made to the contents of the given elem.

Limitations

  • Do not use an id attribute to style elements that match the itemSelector. (It is okay to add an id to these elements as a fragment identifier.)

Installation

Install via npm:

$ npm i --save @yuanqing/sticky

Install via bower:

$ bower i --save yuanqing/sticky

Changelog

  • 0.1.0
    • Initial release

License

MIT