Skip to content

Instantly share code, notes, and snippets.

@DevShahidul
Last active September 23, 2017 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevShahidul/dff6532a32dd57b33f92aeca0705f4d8 to your computer and use it in GitHub Desktop.
Save DevShahidul/dff6532a32dd57b33f92aeca0705f4d8 to your computer and use it in GitHub Desktop.
This code for drop down navigation function
$('.main-nav ul li, .footer-nav-mobi ul li').find('ul').addClass('dropdownNav')
$('.main-nav ul li, .footer-nav-mobi ul li').find('ul').parent().addClass('hasDropdown')
if($(window).width() < 768){
$('.main-nav ul li.hasDropdown > a, .footer-nav-mobi ul li.hasDropdown a').bind('click','touchend', function(e){
e.preventDefault()
$('.main-nav li.hasDropdown, .footer-nav-mobi ul li.hasDropdown').removeClass('active')
$(this).parent().addClass('active')
$('.main-nav li.hasDropdown, .footer-nav-mobi ul li.hasDropdown').find('> ul:visible').slideUp()
if($(this).parent().find('> ul:visible').length){
$(this).parent().find('> ul').slideUp()
$(this).parent().removeClass('active')
}
else{
$(this).parent().find('> ul').slideDown()
$(this).parent().addClass('active')
}
})
}
//Another one
if( $(window).width() < 768 ){
$('.main-nav li.hasSubnav > a').bind('click', 'touchend', function(e){
e.preventDefault()
$('.main-nav li.hasSubnav').find('> ul:visible').slideUp()
if( $(this).parent().find('> ul:visible').length ){
$(this).parent().find('> ul').slideUp()
}
else{
$(this).parent().find('> ul').slideDown()
}
})
$('.main-nav li.hasSubmenu > a').bind('click', 'touchend', function(e){
e.preventDefault()
$('.main-nav li.hasSubmenu').find('> ul:visible').slideUp()
if( $(this).parent().find('> ul:visible').length ){
$(this).parent().find('> ul').slideUp()
}
else{
$(this).parent().find('> ul').slideDown()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment