jQuery Plugin For Better CSS Position:Sticky - Sticky.js

File Size: 112 KB
Views Total: 2888
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
jQuery Plugin For Better CSS Position:Sticky - Sticky.js

Sticky.js is a jQuery plugin to enhance the CSS position: sticky property that makes your sticky element fit within the viewport height.

The plugin has the ability to automatically enable/disable the function depending on the current screen size.


$ npm install sticky.jquery.js --save

How to use it:

1. Create a normal sticky element using CSS position: sticky property.

<aside class="sidebar sticky-sidebar-css">
  <h3>Sticky Sidebar</h3>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ut urna
    id nisi mollis sagittis. Donec erat tellus, dignissim id elit a, lacinia
    dignissim odio. Vestibulum ac ligula libero. Ut id ullamcorper est, id
    porttitor mi. Phasellus vel ligula sit amet mauris suscipit lacinia.
    Maecenas orci metus, iaculis sed fringilla nec, aliquam sit amet augue.
    Integer lorem dolor, convallis ut arcu sed, feugiat rutrum ante.
.sticky-sidebar-css {
  position: sticky;
  position: -webkit-sticky;
  top: 0; /* required */

2. Download and insert the jQuery Sticky.js plugin after jQuery JavaScript library.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="sticky.jquery.min.js"></script>

3. Enable the plugin with just one line of code:

(function($) {



4. Set the default CSS position property:

   * This should be the position if you wouldn't use "position: sticky;". If
   * the element was positioned absolute then you would specify absolute.
   * Otherwise relative.
  defaultPosition: 'relative',

5. Enable/disable the plugin based on the screen size.

  breakpoints: [
      min: 0,
      max: 768,



  • fixed working version on safari; fixed calcalculation when scrolling up;


  • v2.1.4


  • check if element exists on the page;

This awesome jQuery plugin is developed by kkoomen. For more Advanced Usages, please check the demo page or visit the official website.