/*ljcong 2017.10.28*/ var menu_icon=''; var menu_bg='
'; function menu(menu_id,speed,menu_index){ var w_width=$(window).width(); $(menu_id).addClass('menu-style'); $(menu_id+'>ul>li>:first-child').unbind('click').removeClass('on'); $(menu_id+'>ul>li>:first-child').eq(menu_index).addClass('on'); if(w_width>1024){ $(menu_id+'>ul>li>:nth-child(2)').removeAttr('style');//移除因手机而叠加的style,如用js添加效果可删除 $('#menu-i,#public-bg').remove(); $('body').removeClass('on'); $(menu_id).show().removeAttr('style'); $(menu_id+'>ul>li').hover(function(){ $(menu_id+'>ul>li>:first-child').eq(menu_index).removeClass('on'); }, function() { $(menu_id+'>ul>li>:first-child').eq(menu_index).addClass('on'); }); } else{ $(menu_id+'>ul>li').unbind('mouseenter').unbind('mouseleave'); $('#menu-i,#public-bg').remove(); $(menu_id).after(menu_icon);//设置0 预防窗口放大动画还未结束 导致导航隐藏问题 $(menu_id+'>ul>li>:nth-child(2)').slideUp(0).prev().removeAttr('href');//单极a移除 $(menu_id+'>ul>li>:nth-child(2)').prev().find('a').removeAttr('href');//预防多级 $(menu_id+'>ul>li>:first-child').click(function(){ $(menu_id+'>ul>li>:first-child').removeClass('on'); $(this).addClass('on').next().slideToggle(speed).parent().siblings().children(':nth-child(2)').slideUp(speed); }); $('#menu-i').click(function(){ if($(this).hasClass('test')){ $(this).removeClass('test'); $('#public-bg').remove(); $('body').removeClass('on'); } else{ $(this).addClass('test').after(menu_bg); $('body').addClass('on'); $(menu_id).find('>ul>li>:nth-child(2)').slideUp(0); } }); } }