window.onload=function(){? ? var wrap=document.getElementById('wrap'),? ? ? ? pic=document.getElementById('pic').getElementsByTagName('li'),? ? ? ? list=document.getElementById('list').getElementsByTagName('li'),? ? ? ? index=0,? ? ? ? timer=null;? ? ? // 定義并調(diào)用自動播放函數(shù) function autoPlay(){ index++; if(index >= pic.length){ index = 0; } changePic(index); } ? ? ? timer = setInterval(autoPlay,2000); ?// 定義圖片切換函數(shù)? ? ? function changPic(thisIndex){ for(var j = 0; j < pic.length; j++){ pic[j].style.display = 'none'; list[j].className = ''; } pic[thisIndex].style.display = 'block'; //pic.style.top = "-" + thisIndex*170 +"px"; list[thisIndex].className = 'on'; } ? ? ?// 鼠標(biāo)劃過整個容器時停止自動播放 wrap.onmouseover = function(){ clearInterval(timer); } ? ? ?// 鼠標(biāo)離開整個容器時繼續(xù)播放至下一張? ? wrap.onmouseout = function(){ timer = setInterval(autoPlay,2000); } ? ? ?// 遍歷所有數(shù)字導(dǎo)航實現(xiàn)劃過切換至對應(yīng)的圖片 for(var i = 0; i< list.length; i++){ list[i].id = i; list[i].onmouseover = function(){ clearInterval(timer); changPic(this.id); } }? ?}
請大神看一下為什么定時器沒有反應(yīng),這是tab選項卡的js
Rosevil1874
2016-09-10 14:48:56