
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
stickythead
Advanced tools
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.
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>
Initializing the plugin is pretty straight forward:
let elements = document.querySelectorAll('table')
stickyThead.apply(elements);
To remove the plugin:
let elements = document.querySelectorAll('table')
stickyThead.apply(elements, 'destroy');
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 });
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 });
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] });
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.<th>
s explicitly in the css in order to make the plugin workThe plugin has been verified to work in:
NOTE: It does not work in Internet Explorer 7 (but it degrades nicely)
FAQs
Sticky table header (Vanilla js)
The npm package stickythead receives a total of 277 weekly downloads. As such, stickythead popularity was classified as not popular.
We found that stickythead demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.