//封裝一個(gè)代替getElementById()的方法
function?byId(id){
return?typeof(id)==="string"?document.getElementById(id):id;
}
var?index=0,
timer=null,
pics=byId("banner").getElementsByTagName("div"),
len=pics.length;
function?slideImg(){
var?main=byId("main");
//滑過清除定時(shí)器,離開繼續(xù)
?main.onmouseover=function(){
? if?(timer)?clearInterval(timer);
?}
main.onmouseout=function(){
timer=setInterval(function(){
index++;
if?(index>=len)?{
index=0;
}
//切換圖片
changeImg();
},3000);
}
main.onmouseout();
}
//切換圖片
function?changeImg(){
//遍歷banner下所有的div,將其隱藏
for?(var?i?=?0;?i?<?i.len;?i++)?{
pics[i].style.display="none";
}
pics[index].style.display="block";
}
slideImg();
為什么14,38行會(huì)報(bào)錯(cuò)呢?onmouseover報(bào)錯(cuò)??
英姿颯爽豆腐塊
2017-09-08 14:50:38