(function($){ $(window).load(function(){ $(".recipe_menu li").hover(function(){ // PCサイズの時、hoverまたはfocusでメニュー展開 if($(window).width() > 768) { if($(this).find("ul").length > 0) { $(this).find("ul").addClass("toggled-on"); } } },function(){ if($(window).width() > 768) { if($(this).find("ul").length > 0) { $(this).find("ul").removeClass("toggled-on"); } } }); $(".recipe_menu li").click(function(){ // SPサイズの時、タップ(click)で展開 if(/*575 < $(window).width() &&*/ $(window).width() < 769) { // if($(this).find("ul").length > 0) { // $(this).find("ul").toggleClass("toggled-on"); // } // }else if($(window).width() < 576){ var current_li = $(this).attr('class'); if($(".recipe_menu li").find("ul").length > 0) { $(".recipe_menu li").each(function(i,e){ if( $(e).attr('class') === current_li ) { $(e).find("ul").toggleClass("toggled-on"); }else{ $(e).find("ul").removeClass("toggled-on"); } }); } } }); }); $(window).resize(function(){ if($(window).width() > 768) { $(".recipe_menu li ul.toggled-on").each(function(i,elem){ $(elem).removeClass("toggled-on"); }); } }); })(jQuery);