Skip to content

Instantly share code, notes, and snippets.

@wireinet
Created October 14, 2019 08:43
Show Gist options
  • Save wireinet/66b98b689854a86ec7974fd6bcb9441e to your computer and use it in GitHub Desktop.
Save wireinet/66b98b689854a86ec7974fd6bcb9441e to your computer and use it in GitHub Desktop.
// submenu
$(function(){
var submenu = $(".sub_menu");
var menu = $(".header_menu_main");
var menu_item = $(".header_menu_main li a");
if(window.matchMedia('(min-width: 480px)').matches){
submenu.parent('li').append('▼');
remove__class = function(){
$(submenu).removeClass("sub_menu_open");
$(submenu).removeClass("sub_menu_close");
};
menu_item.mouseover(function(event){
$(this).siblings(submenu).addClass("sub_menu_open");
});
submenu.mouseleave(function(e){
$(submenu).addClass("sub_menu_close");
setTimeout(remove__class, 100);
});
}
if(window.matchMedia('(max-width: 480px)').matches){
submenu.parent('li').append('<div class="sub_reveal"></div>');
}
$.fn.clickToggle = function(func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function() {
var data = $(this).data();
var tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
$('.sub_reveal').clickToggle(function(){
$(submenu).slideDown();
},
function(){
$(submenu).slideUp();
}
);
});// /submenu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment