代码有点乱
function getId(id){
return typeof id==="string"?document.getElementById(id):id;
};
window.addEventListener("load",function(){
var navList=getId("nav").getElementsByTagName("li");
var contentList=getId("content").getElementsByTagName("div");
var pointer=0;
var timer=null;//和var timer;一样
var selfMotionPlayer=null;
function player(){
selfMotionPlayer=setInterval(function(){
pointer++;
if(pointer>=navList.length){
pointer=0;
}
for(var k=0;k<navList.length;k++){
navList[k].className="";
contentList[k].style.display="none";
}
navList[pointer].className="select";
contentList[pointer].style.display="block";
},2000);
};
function stop(){
clearInterval(selfMotionPlayer);
};
player();
if (navList.length!=contentList.length) {
return ;
}
for(var i=0;i<navList.length;i++){
navList[i].addEventListener("mouseover",function(event){
stop();
if(timer){
clearTimeout(timer);
timer=null;
};
var that=this;
timer=setTimeout(function(){
for(var j=0;j<navList.length;j++){
navList[j].className="";
contentList[j].style.display="none";
};
that.className="select";
contentList[that.getAttribute("index")-1].style.display="block";
pointer=that.getAttribute("index")-1;
},400);
},false);
navList[i].addEventListener("mouseout",function(){
player();
},false);
}
},false);