Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // Create a clone of the menu, right next to original.
  2. $('.menu').addClass('original').clone().insertAfter('.menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();
  3.  
  4. scrollIntervalID = setInterval(stickIt, 10);
  5.  
  6.  
  7. function stickIt() {
  8.  
  9. var orgElementPos = $('.original').offset();
  10. orgElementTop = orgElementPos.top;
  11.  
  12. if ($(window).scrollTop() >= (orgElementTop)) {
  13. // scrolled past the original position; now only show the cloned, sticky element.
  14.  
  15. // Cloned element should always have same left position and width as original element.
  16. orgElement = $('.original');
  17. coordsOrgElement = orgElement.offset();
  18. leftOrgElement = coordsOrgElement.left;
  19. widthOrgElement = orgElement.css('width');
  20. $('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show();
  21. $('.original').css('visibility','hidden');
  22. } else {
  23. // not scrolled past the menu; only show the original menu.
  24. $('.cloned').hide();
  25. $('.original').css('visibility','visible');
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement