<div class="head">
<ul id="nav">
<li class="current">首页</li>
<li>功能特色</li>
<li>产品部署</li>
<li>功能下载</li>
</ul>
<span id="tag"></span>
</div>
<script type="text/javascript">
$(document).ready(function(){
var aLeft = [];
$("#nav li").each(function(index){
aLeft[index] = $("#nav li").eq(index).offset().left + $("#nav li").eq(index).width()/2+10;
});
$("#nav li").mousemove(function(){
var index = $(this).index("#nav li");
switch(index){
case 0:
$("#tag").stop().animate({"left":aLeft[0]},100);
break;
case 1:
$("#tag").stop().animate({"left":aLeft[1]},100);
break;
case 2:
$("#tag").stop().animate({"left":aLeft[2]},100);
break;
case 3:
$("#tag").stop().animate({"left":aLeft[3]},100);
break;
}
});
$("#nav li").mouseout(function(){
var index = $("#nav li.current").index("#nav li");
switch(index){
case 0:
$("#tag").stop().animate({"left":aLeft[0]},100);
break;
case 1:
$("#tag").stop().animate({"left":aLeft[1]},100);
break;
case 2:
$("#tag").stop().animate({"left":aLeft[2]},100);
break;
case 3:
$("#tag").stop().animate({"left":aLeft[3]},100);
break;
}
});
});
</script>
index索引的用法: var index = $(this).index("#nav li");
匿名函数:
(function(){
})();
如:
(function(x, y){ alert(x + y); })(2, 3);