各位大佬真的不知道哪里错了,物体都不能运动了
window.onload = function () {
var aLi = document.getElementsByTagName('li');
for(var i = 0;i<aLi.length;i++){
aLi[i].timer = null;
aLi[i].onmouseover = function () {
startMove(this,400);
}
aLi[i].onmouseout = function (){
startMove(this,200);
}
}
//var timer = null;
function getStyle(obj,attr){
if(obj.currentStyle[attr]){
return obj.currentStyle[attr];//针对ie浏览器。
}else{
return getComputedStyle(obj,false)[attr];//针对firefox浏览器。
}
}
var alpha=0.3;
function startMove(obj,iTarget) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var icur=parseInt(getStyle(obj,'width'));
var speed = (iTarget-icur)/8;
speed = speed >0?Math.ceil(speed):Math.floor(speed);
if(icur== iTarget){
clearInterval(obj.timer);
}
else {
obj.style.width=icur+speed+"px";
//obj.style.fontSize=parseInt(getStyle(obj,'font-size')+speed+'px'
}
},30)}
}