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

stickythead

v1.0.4

Published

Sticky table header (Vanilla js)

Downloads

1,840

Readme

StickyThead

NOTE: This is vanila js version of https://github.com/jmosbech/StickyTableHeaders. Even docs are copy pasted :)

So what's it good for? Well, let's say you want to display a long list of fairly uniform tabluar data, like stock exchange listings or sport statistics but you don't want your users to get lost in the data as they scroll down on the page.

StickyThead to the rescue: By applying the StickyThead jQuery plugin to the table, the column headers will stick to the top of the viewport as you scroll down.

The code is based on this proof of concept.

Installation

The best way to install is using npm:

npm install stickythead

or by loading it directly from the unpkg CDN:

<script src="https://unpkg.com/stickythead"></script>

Usage

Initializing the plugin is pretty straight forward:

let elements = document.querySelectorAll('table')
stickyThead.apply(elements);

Tear down

To remove the plugin:

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, 'destroy');

Options

You can initialize the plugin with an options map to tweak the behavior. The following options are supported:

fixedOffset

A number or jQuery object specifying how much the sticky header should be offset from the top of the page:

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, { fixedOffset: document.querySelector('#header') });

scrollableArea

A DOM element or jQuery object. Allows you to overwrite which surrounding element is scrolling. Defaults to window.

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, { scrollableArea: document.querySelector('.scrollable-area') });

cacheHeaderHeight

Performance tweak: When set to true the plugin will only recalculate the height of the header cells when the width of the table changes.

Default value: false

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, { cacheHeaderHeight: true });

z-index

The plugin uses z-index to make the thead overlay the body. You can override the z-index value by passing in a zIndex option:

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, { zIndex: 999 });

Reinitialize

As described in pull request #33 responsive pages might need to reinitialize the plugin when the user resizes his browser. This is can be done by calling the plugin with the new options:

let elements = document.querySelectorAll('table')
stickyThead.apply(elements, { fixedOffset: [new-offset] });

Events

The plugin triggers the following events on the targeted <table> element:

  • clonedHeader.stickyTableHeaders: When the header clone is created.
  • enabledStickiness.stickyTableHeaders: When the sticky header is enabled.
  • disabledStickiness.stickyTableHeaders: When the sticky header is disabled.

Known Issues

  • Internet Explorer: You need to set the padding of the <th>s explicitly in the css in order to make the plugin work
  • Internet Explorer: Adding horizontal margin to the table causes the header to be misaligned when scrolling. (Issue #10)
  • Using the plugin together with tablesorter breaks in Internet Explorer 8

Browser Support

The plugin has been verified to work in:

  • Chrome 35
  • Firefox 29
  • Internet Explorer 8-11
  • Safari 5

NOTE: It does not work in Internet Explorer 7 (but it degrades nicely)