I've built a mobile menu (.menu-wrap) that includes a link (#bottom-section), which toggles a sub-menu (#support-us-nav) in the DOM, but it's not visible until the user scrolls down.
I'm trying to modify my jQuery, which toggles the sub-menu, to also scroll the main menu, which is partly working. The main menu scrolls down on click, but it scrolls all the way to the bottom until it reaches the sub-menu's bottom, which is the last element in the main menu. I'd like the main menu to scroll until the sub-menu's top reaches the top of the viewport.
$('#bottom-section').on('click', function(event) {
event.stopPropagation();
$('#support-us-nav').fadeToggle();
$('#lc-nav .menu-wrap').animate({
scrollTop: $('#support-us-nav').offset().top
}, 1000);
});
HTML structure:
<div class="menu-wrap">
<div class="menu-sidebar">
<div id="nav-account" class="mobile-only"></div>
<ul id="top-section" class="submenu"></ul>
<ul id="middle-section" class="submenu"></ul>
<ul id="bottom-section" class="submenu"></ul>
<div id="support-us-nav"></div>
</div>
</div>