Skip to content

Instantly share code, notes, and snippets.

@erikyo
Last active November 23, 2017 22:28
Show Gist options
  • Save erikyo/fd6f67328ed010ce1f2cc457a216b585 to your computer and use it in GitHub Desktop.
Save erikyo/fd6f67328ed010ce1f2cc457a216b585 to your computer and use it in GitHub Desktop.
Wordpress menu dropdown jquery
/**
* Menu scripts
*/
(function ($, root, window) {
'use strict';
//DROPDOWN MENU
$(document).ready(function () {
// Opera Fix
$('.menu_container li').children('ul').hide();
// Insert before the submenu (ul.subnav) an arrow
$('.menu_container li').has('ul.sub-menu').append("<span class='resparrow'><i class='material-icons'>keyboard_arrow_right</i></span>");
// When trigger is clicked
$("ul.menu li").click(function() { //When trigger is clicked...
//Following events are applied to the subnav itself (moving subnav up and down)
if ($(this).find("ul.sub-menu").is(':hidden') == true) {
$(this).parent().find("ul.sub-menu").addClass('slided').slideDown('slow').show(400); //Drop down the subnav on hover
return false;
}
});
//When the mouse hovers out of the subnav, move it back up
$("ul.sub-menu").hover(function() {
}, function(){
jQuery(this).removeClass('slided').slideUp('fast');
});
// if the arrow is clicked slide-up the submenu
$("span.resparrow").click(function() {
}, function(){
$(this).parent().find("ul.sub-menu").removeClass('slided').slideUp('fast');
});
});
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment