$(function(){ /*-------------------公共部分---------------*/ var oNav = $('.nav01'); var oNavLi = $('.nav01 .level01>li'); var timeout01 = null; var clientW = $(window).width(); /*-------------------下拉列表第一版---------------*/ var navList = $('.nav01 .navList01'); //navList里面a标签hover navList.find('a').hover(function () { $(this).css('color', '#cb212e'); }, function () { $(this).css('color', '#fff'); }); // 小圆点位置 navList.find('.level02 i').each(function(index,ele){ $(ele).css({ top:11 }) }); //navList li超出边界,就向左 oNavLi.each(function (index, ele) { var rectLeft = $(ele)[0].getBoundingClientRect().left; var navUlW = $(ele).find('.navList01').width(); if (rectLeft + navUlW > clientW) { $(ele).find('.navList01').css({left: 'auto', right: 0}) } }); //li鼠标移入 oNavLi.on({ 'mouseenter': function () { var self = $(this); timeout01 = setTimeout(function () { self.addClass('active').siblings('li').removeClass('active'); self.siblings('li').find('.navList01').stop(true).slideUp(200); self.find('.navList01').stop(true).slideDown(200, function () { $(this).css({height: 'auto'}) }); }, 100) }, 'mouseleave': function () { clearTimeout(timeout01); oNavLi.removeClass('active'); } }); //大的nav移出 oNav.on({ 'mouseenter': function () { }, 'mouseleave': function () { navList.stop(true).slideUp(200); } }); });