Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
stickybits
Advanced tools
Stickybits is a lightweight (<2KB) alternative to `position: sticky` polyfills
Make things get sticky …in a good way
Stickybits is a lightweight (<2KB) alternative to
position: sticky
polyfills that works perfectly for things like sticky headers.
Stickybits is awesome because:
.js-is-sticky
) when position: sticky elements become active and a CSS Stuck Class (.js-is-stuck
) when they become stuck. See useStickyClasses.position: fixed
have because it tries to support position: sticky
first.scroll
event listener will not be used if position: sticky
is supported.Installation Setup Usage Feature Options Examples Notes
yarn
yarn add stickybits
npm
npm install stickybits --save
bower
bower install stickybits --save
Add dist/stickybits.min.js.
stickybits('selector');
useStickyClasses
FeatureStickybits allows customers to add CSS to elements when they become sticky and when they become stuck at the bottom of their parent element.
By default, if position: sticky
is supported, StickyBits will exit allowing the browser to manage stickiness and avoid adding a scroll
event listener.
If the useStickyClasses
argument is set to true
then even if a browser supports position: sticky
, StickyBits will still add a scroll
event listener to add and remove sticky CSS Classes. This option is available so that CSS styles can use when StickyBits elements become sticky or stuck at the bottom of their parent.
To use useStickyClasses
:
stickybits('selector', {useStickyClasses: true});
Then, in css you can do:
.some-sticky-element .js-is-sticky {
background-color: red;
}
.some-sticky-element .js-is-stuck {
background-color: green;
}
View add css classes for more information on StickyBits CSS Classes.
By default, a StickyBits element will stick to the top of the viewport when vertically scrolled to.
Stickybits loosely works for bottom
positioning as well.
To have a StickyBits element stick to the bottom
:
stickybits('selector', {verticalPosition: 'bottom'});
By default, a StickyBits element will have a 0px
sticky layout top offset. This means that the element will stick flush to the top of the viewport.
To have a StickyBits element stick with a 20px
offset to its vertical layout position:
stickybits('selector', {stickyBitStickyOffset: 20});
For jQuery and Zepto support, read in the jQuery notes below.
stickybits('selector', {stickyBitStickyOffset: 20})
stickybits('selector', {customVerticalPosition: true})
stickybits('selector', {useStickyClasses: true})
$('selector').stickybits();
Have another example or question? Feel free to comment. 🙌
3 CSS classes will be added and removed by Stickybits if position: sticky
is not supported or if the useStickyClasses: true
option is added to the plugin call.
js-is-sticky
if the selected element is sticky.js-is-stuck
if the selected element is stopped at the bottom of its parent.js-stickybit-parent
so that styles can easily be added to the parent of a Stickybits elementWe strayed away from calling Stickybits a Shim or Polyfill for position: sticky
because full support would require more code. This plugin simply makes elements vertically sticky very similarly to position: fixed
but in a sticky
sort of way. Read more about position sticky here or follow its browser implementation here.
Basic
$('selector').stickybits();
With useStickyClasses
$('selector').stickybits({useStickyClasses: true});
With customVerticalPosition
$('selector').stickybits({customVerticalPosition: true});
With stickyBitStickyOffset
$('selector').stickybits({stickyBitStickyOffset: 20});
This plugin was heavily influenced by Filament Group's awesome Fixed-sticky jQuery plugin. Thanks to them for getting my mind going on this a while back. Thanks to Peloton Cycle's Frame Throttle for an insightful solve for optimizing frame throttling
.
FAQs
Stickybits is a lightweight alternative to `position: sticky` polyfills
The npm package stickybits receives a total of 31,362 weekly downloads. As such, stickybits popularity was classified as popular.
We found that stickybits 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.