Hello,
I am building a very simple one-pager with three anchors that you can jump to in the menu. That also works quite fine with the mobile burger navigation. But I want the navigation to close after a menu item has been clicked.
To close the navigation after clicking on one menu item I used some code line I found here:
http://laythemeforum.com:4567/topic/4005/collapse-mobile-nav-on-click-menu-item but
But sadly the suggested solution doesn't work as expected. It actually messes up the scrollTo action, so now it scrolls up to the top and than to the anchor. And I don't understand why. I also tried the suggested toggleClass, but it worked even less.
This is the script I have in Custom HTML at bottom:
<script>
jQuery(document).ready(function(){
jQuery('body').on('click', 'li.menu-item > a', function(event) {
event.preventDefault();
var id = jQuery(this).attr('href');
jQuery('html, body').animate( { scrollTop: jQuery(id).offset().top }, 750 );
});
jQuery(document).on("click", ".mobile-nav ul li a", function(event) {
jQuery(".mobile-nav").removeClass('active');
jQuery(".mobile-nav").css('transform','translateY(-180px)');
});
});
</script>
This is the link to the page I am talking about: http://wendelstein-steuerberatung.de
I am very much looking forward to your answer.
Best regards, Miriam