Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. init();
  2.  
  3. function init() {
  4. hideMobileNavOnClick();
  5. }
  6.  
  7. function hideMobileNavOnClick() {
  8. var $ = jQuery,
  9. menu = $('.main-navigation'),
  10. inlineLinks = menu.find('a[href*="#"]');
  11.  
  12. if (inlineLinks.length !== 0) {
  13. inlineLinks.each(function() {
  14. var link = $(this),
  15. linkHref = link.attr('href'),
  16. linkHash = linkHref.substr(linkHref.indexOf("#")),
  17. // Search ID or Name attributes
  18. target = $(linkHash).add('[name="' + linkHash.substr(1) + '"]');
  19.  
  20. if (target.length !== 0) {
  21.  
  22. link.on('click', function(event) {
  23. var menuBtn = menu.find('.menu-toggle');
  24.  
  25. // If mobile
  26. if (!menuBtn.is(':hidden')) {
  27. // Hide the menu
  28. menuBtn.click();
  29. }
  30.  
  31. });
  32. }
  33. });
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement