Guest User

Untitled

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