First include the shortcut script.
<script src="/path/to/waypoints-sticky.min.js"></script>
The Sticky Elements shortcut is used to make elements "stick" to the top of the page when the user scrolls past. It packages a few best practices around this pattern into one simple function extension of jQuery Waypoints. The most basic usage looks like this:
$('.my-sticky-element').waypoint('sticky');
stuck
class.stuck
elements fixed positioning. It is left to you, the author, to give the stuck elements fixed positioning in CSS. With so many design possibilities, the script cannot make any assumptions about how the sticky element should look. The shortcut only goes as far as to add the class to give you a hook for this styling.The "sticky" waypoint method may also be passed an options object. This options object can be used to override the class name of the "stuck" state and the HTML of the wrapper element. Here are the defaults:
$('.my-sticky-element').waypoint('sticky', {
wrapper: '<div class="sticky-wrapper" />',
stuckClass: 'stuck'
});
This options object is just an extension of the regular Waypoints options object, so you can pass along any traditional options you may want. A common one is the offset
option.
$('.my-sticky-element').waypoint('sticky', {
offset: 30 // Apply "stuck" when element 30px from top
});