I created a site with mobile navigation,
I use jQuery to create a slide, but I have a few checks in place. To find out if the user has opened the search / notification panel. Then the hiding is shown, so that you see only one of the elements for a given time.
My jQuery code is as follows (I also provided a script)
$(document).ready(function() { // Mobile Nav Toggle... $('.nav-toggle').click(function() { // // Check If Other Items Are Open.... if($('.mobile-search-form:visible')) { $('.mobile-search-form').hide(); } // // Check If Other Items Are Open.... if($('.mobile-notifications:visible')) { $('.mobile-notifications').hide(); } $('nav').slideToggle(); accordion_links(); return false; }) // Add a Chevron Class To Links (For Mobile Nav)... $(function() { $('nav ul li a').each(function() { if ( $(this).parent('li').children('ul').size() > 0 ) { $(this).addClass('chevron-down'); } }); }); function accordion_links() { $('.chevron-down').click(function() { $(this).next('ul.sub-nav').slideToggle(); if($(this).parent('li').hasClass('open')) { $(this).removeClass('chevron-up'); $(this).addClass('chevron-down'); $(this).parent('li').removeClass('open'); } else { $(this).removeClass('chevron-down'); $(this).addClass('chevron-up'); $(this).parent('li').addClass('open'); } }) } // Toggle Search Form (On Mobile).... $('.search-link').click(function() { // Check If Notifications / Search Form Are Visible... if($('nav:visible')) { $('nav').slideUp(); } if($('.mobile-notifications:visible')) { $('.mobile-notifications').hide(); } $('.mobile-search-form').slideToggle(); return false; }) // Toggle Notifications On Mobile... $('a.notifications').click(function() { // Check If Notifications / Search Form Are Visible... if($('nav:visible')) { $('nav').hide(); } if($('.mobile-search-form:visible')) { $('.mobile-search-form').hide(); } $('.mobile-notifications').slideToggle(); return false; }) // Close Notification Block $('.close-notification').click(function() { $('.notification').fadeOut(); }) })
The problem I encountered is whether the switch first fires, but when you click on the search link, then load the navigator. The slideToggle method tries to make an animation twice (Open, then Close)
A jsFiddle is here
Why do this? I can only assume that my logic is wrong in that.
source share