Guest User

Untitled

a guest
Jan 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /**
  2. * Setup Header
  3. **/
  4. setupHeader() {
  5.  
  6. var scrollOffset = parseInt($('#header').outerHeight());
  7.  
  8. // if one-page menu items click
  9. $('a[href*="#!/"]').click(function () {
  10.  
  11. var $link = $(this),
  12. url = $link.attr('href');
  13.  
  14. // is one page link
  15. if (url.indexOf('#!/') !== -1) {
  16.  
  17. var linkParts = url.split('#!/'),
  18. sectionID = linkParts[1],
  19. $section = $('#' + sectionID);
  20.  
  21. if ($section.length) {
  22.  
  23. $('html, body').animate({
  24. scrollTop: parseInt($section.offset().top - scrollOffset)
  25. }, 800, function () {
  26. // Add hash (#) to URL when done scrolling (default click behavior)
  27. window.location.hash = '#!/' + sectionID;
  28. });
  29.  
  30. return false;
  31.  
  32. }
  33.  
  34. }
  35.  
  36. });
  37.  
  38. var hash = window.location.hash;
  39. // if page URL contains one-page hash
  40. if (hash.indexOf('#!/') !== -1) {
  41.  
  42. var linkParts = hash.split('#!/'),
  43. sectionID = linkParts[1],
  44. $section = $('#' + sectionID);
  45.  
  46. if ($section.length) {
  47.  
  48. setTimeout(function () {
  49.  
  50. $('html, body').animate({
  51. scrollTop: parseInt($section.offset().top - scrollOffset)
  52. }, 800, function () {
  53.  
  54. $('#header_menu li').removeClass('current-menu-item');
  55.  
  56. $('#header_menu a').each(function () {
  57.  
  58. if ($(this).attr('href').indexOf(hash) !== -1) {
  59. $(this).parent().addClass('current-menu-item');
  60. }
  61.  
  62. });
  63.  
  64. // Add hash (#) to URL when done scrolling (default click behavior)
  65. window.location.hash = '#!/' + sectionID;
  66.  
  67. });
  68.  
  69. }, 1000);
  70.  
  71. return false;
  72.  
  73. }
  74.  
  75. }
  76.  
  77. }
Add Comment
Please, Sign In to add comment