Posted By

phiqle on 01/30/12


Tagged

nav position fixed sticky


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

spee66
BrockSamsom


Make a Sticky Nav


 / Published in: jQuery
 

Makes an element stick during scroll.

  1. var $windowTag = $(window);
  2. var $fixedElement = $("nav");
  3. var fixedElementOffSet = $fixedElement.offset().top;
  4.  
  5. $windowTag.scroll(function() {
  6.  
  7. var scrollTop = $windowTag.scrollTop();
  8.  
  9. if (fixedElementOffSet < scrollTop) {
  10. $fixedElement.addClass("fixed");
  11. } else {
  12. $fixedElement.removeClass("fixed");
  13. }
  14. });

Report this snippet  

You need to login to post a comment.