diff --git a/_sass/navigation.scss b/_sass/navigation.scss index c836ecb1bc..ed62e975f9 100644 --- a/_sass/navigation.scss +++ b/_sass/navigation.scss @@ -223,6 +223,7 @@ a.nav-text:hover { .stellarnav.mobile { & .nav-list{ + display: none; position: absolute; width: 100%; left:0; diff --git a/js/stellarnav.js b/js/stellarnav.js index f75568fbe7..224833aaf2 100644 --- a/js/stellarnav.js +++ b/js/stellarnav.js @@ -169,33 +169,7 @@ } // opens and closes menu - $('.menu-toggle, .stellarnav-open').on('click', function(e) { - e.preventDefault(); - - // if nav position is left or right, uses fadeToggle instead of slideToggle - if (settings.position == 'left' || settings.position == 'right') { - nav.find('ul:first').stop(true, true).fadeToggle(settings.openingSpeed); - nav.toggleClass('active'); - - if(nav.hasClass('active') && nav.hasClass('mobile')) { - // closes the menu when clicked outside of it - $(document).on('click', function(event) { - // ensures menu hides only on mobile nav - if(nav.hasClass('mobile')) { - if (!$(event.target).closest(nav).length) { - nav.find('ul:first').stop(true, true).fadeOut(settings.openingSpeed); - nav.removeClass('active'); - } - } - }); - } - - } else { - // static position - normal open and close animation - nav.find('ul:first').stop(true, true).slideToggle(settings.openingSpeed); - nav.toggleClass('active'); - } - }); + $('.menu-toggle, .stellarnav-open').on('click', toggleMenu); // activates the close button $('.close-menu, .stellarnav-close').on('click', function() { @@ -224,6 +198,25 @@ // expands the dropdown menu on each click of nav-text nav.find('li .sub-list').on('click', navbarExpand); + nav.find('li.nav-item').not('.has-sub').on('click', (e) => { + if (nav.hasClass('mobile')){ + toggleMenu(e); + } + var href = $(e.currentTarget).find('a').attr('href') + + if (href.startsWith('/#') || href.startsWith('#')){ + var targetId = href.startsWith('/#') ? href.substring(2) : href.substring(1) + var target = $('#' + targetId) + + if (target.length){ + $('html, body').animate({ + scrollTop: target.offset().top + }, 800) + } + } + window.location.href = href; + } ) + function navbarExpand(e) { e.preventDefault(); $(this).parent('li').children('ul').stop(true, true).slideToggle(settings.openingSpeed); @@ -269,6 +262,34 @@ }); } + function toggleMenu(e) { + e.preventDefault(); + + // if nav position is left or right, uses fadeToggle instead of slideToggle + if (settings.position == 'left' || settings.position == 'right') { + nav.find('ul:first').stop(true, true).fadeToggle(settings.openingSpeed); + nav.toggleClass('active'); + + if(nav.hasClass('active') && nav.hasClass('mobile')) { + // closes the menu when clicked outside of it + $(document).on('click', function(event) { + // ensures menu hides only on mobile nav + if(nav.hasClass('mobile')) { + if (!$(event.target).closest(nav).length) { + nav.find('ul:first').stop(true, true).fadeOut(settings.openingSpeed); + nav.removeClass('active'); + } + } + }); + } + + } else { + // static position - normal open and close animation + nav.find('ul:first').stop(true, true).slideToggle(settings.openingSpeed); + nav.toggleClass('active'); + } + } + windowCheck(); // check browser width in real-time