Jquery-sticky

A jQuery plugin to easily add functionality to fix elements to the top of the page on scroll.

View project onGitHub

jQuery Sticky Plugin

A jQuery plugin to easily add functionality to fix elements to the top of the page on scroll.

Installation

Include script after the jQuery library:

<script type="text/javascript" src="/path/to/jquery-sticky.js"></script>

Usage

$('.menu').sticky( options )

Options

stickyClass (string)

An optional class to be added to the element.

stickyClass: 'sticky'

anchorClass (string)

An optional class to be added to the generated anchor.

anchorClass: 'sticky-anchor'

activeClass (string)

Set the class that will be added to the element when it is fixed to the top of the page.

activeClass: 'active'

buffer (number)

Option to add a buffer to the top of the sticky element in the form of a number representing the size of the buffer in pixels.

buffer: 20

TODO

  • If the height of the sticky element is changed (for example when active) the anchor retains the original height

License

MIT License (c) Bruno Tarmann & Gareth Nolan