定時(shí)器框架:
window.onload=function(){
let div=document.getElementsByTagName('div');
for(let i=0;i<div.length;i++){
div[i].timer=null;
div[i].onmouseover=function(){
a(this,500);
}
div[i].onmouseout=function(){
a(this,100);
}
}
}
var timer=null;
function a(obj,len){ //距離无拗,對(duì)象
clearInterval(obj.timer); //指定對(duì)象的定時(shí)器
timer=setInterval(function(){
var speed=(len-obj.offsetWidth)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==len){
clearInterval(obj.timer);
}else{
obj.style.width=obj.offsetWidth+speed+"px";
}
},10)
}