jqueryjquery-waypoints

how implement a sticky element and an offset with Waypoints js


I'm using waypoints js (http://imakewebthings.com/waypoints/). I'm using the jquery version and the sticky shortcut:

<script src="/includes/imakewebthings-waypoints-34d9f6d/lib/jquery.waypoints.min.js"></script>
<script src="/includes/imakewebthings-waypoints-34d9f6d/lib/shortcuts/sticky.min.js"></script>

css:

.stuck {
  position:fixed;
  top:0;
}

How would I stick something a certain distance from the top of the screen? I have some elements that I want to stick to the top of the screen and others I want a certain distance from the top. How would I do that?

I tried:

var sticky = new Waypoint.Sticky({
    element: $('#pin-last')[0],
    offset: 80
});

...but it didn't work.


Solution

  • Define what takes place once the element hits that offset point. To do this add a stuckClass to it. Example:

    var sticky = new Waypoint.Sticky({
      element: $('#pin-last')[0], 
      stuckClass: 'stuck',       
      offset: 80                 
    });
    

    Then, in CSS add:

    .stuck {
      position: fixed;
      top: 80px; 
    }