Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. var hashScrollFix = function() {
  2. var hash = location.hash
  3. , menu = $('.main-navi.fixed') // your fixed menu selector
  4. , itm;
  5.  
  6. // I added menu.position().top >= 0 because I fade my menu to above viewport
  7. // with a negative top position
  8. if ( menu.is(':visible') && menu.position().top >= 0 ) {
  9. itm = $(hash);
  10.  
  11. if ( !itm || !itm.offset() || !itm.offset().top )
  12. return;
  13.  
  14. var jump = function() {
  15. // adjust scroll
  16. return $('body').scrollTop(itm.offset().top - menu.outerHeight());
  17. }
  18.  
  19. // on load
  20. jump();
  21.  
  22. // chances are we may need to jump again
  23. setTimeout(jump, 100);
  24. }
  25. }
  26.  
  27. $(window).bind('hashchange', function() {
  28. return hashScrollFix();
  29. });
  30.  
  31. var makeMyMenuFixed = function() {
  32. // .... do things that render a fixed menu
  33.  
  34. // then adjust scroll
  35. // if you are using animation, then you might want to wait until it is done
  36. // e.g .animate(.., .., hashScrollFix)
  37. hashScrollFix();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement