sticky

Stick elements to the top of the viewport when the user scrolls down.

Stars
87

Sticky JS

Elements stick to the top of the viewport when the user scrolls down.

Installation

$ component install pazguille/sticky

See: https://github.com/component/component

Standalone

Also, you can use the standalone version:

<script src="sticky.js"></script>

How-to

sticky(node, {
   boundary: 200,
   fn: function () {}
});
sticky();
sticky(node);
sticky(node, 200);
sticky(node, function () {});

API

sticky([el], [options])

Elements stick to the top of the viewport when the user scrolls down.

  • el: (node || nodeList) [optional] A given node or nodeList.
  • options.boundary: (number) [optional] Pixels from top of window to the element's top.
  • options.fn: (function) [optional] Function to be executed when the element will be fixed.
sticky(node, {
   boundary: 200,
   fn: function () {}
});

sticky.destroy(el)

Elements stick to the top of the viewport when the user scrolls down.

  • el: (node) A given node.
sticky.destroy(node);

Maintained by

License

Licensed under the MIT license.

Copyright (c) 2013 @pazguille.