$(document).ready(function(){ var menusize = $('#nav li').size(); $('#nav li').each(function(index, element) { $(this).width(math.floor(100/menusize)+'%') }); //主导航当前页 var bodyid = $('body').attr('id'); var nav_left = parseint($('#nav').css('margin-left')); if (bodyid){ var re = /[a-za-z]/g; var id = parseint(bodyid.replace(re, '')); var currli=$('#nav li').eq(id); currli.addclass('curr').attr('id','currpage'); var thewidth = parseint(currli.innerwidth()); var theleft = currli.position().left + nav_left; moveslide(thewidth,theleft) }; /*主导航下拉效果*/ $('#nav li').hover(function(){ $('#currpage').removeclass('curr'); $(this).addclass('curr').children('p').stop(true,true).slidedown('fast'); var thewidth = parseint($(this).innerwidth()); var theleft = $(this).position().left + nav_left; moveslide(thewidth,theleft) },function(){ $(this).removeclass('curr').children('p').stop(true,true).slideup('fast'); $('#currpage').addclass('curr'); }); $('#nav').mouseleave(function(){ if(currli){ var thewidth = parseint(currli.innerwidth()); var theleft = currli.position().left + nav_left; }else{ thewidth = 0; theleft = 0; } moveslide(thewidth,theleft) }) function moveslide(thewidth,theleft){ $('#slide').stop(true,true).animate({'width':thewidth+'px','left':theleft+'px'},250); } /*把电话号码替换成图片*/ if($('#telephone').length>0){ var digitalwid=14; var obj=$('#telephone').html(); var newobj; for(i=0;i<=9;i++){ var re = eval("/"+i+"/g"); obj=obj.replace(re,''); } $('#telephone').html(obj); } /*分类*/ $('#list li a').click( function() { var checkelement = $(this).next(); if((checkelement.is('p')) && (checkelement.is(':visible'))) { checkelement.slideup('normal'); return false; } if((checkelement.is('p')) && (!checkelement.is(':visible'))) { $(this).parent('li').addclass('hover').siblings().removeclass('hover'); $('#list p:visible').slideup('normal'); checkelement.slidedown('normal'); return false; } } ); });