function startmove(obj, json, fnend) { if(obj.timer) { clearinterval(obj.timer); } obj.timer=setinterval(function (){ domove(obj, json, fnend); }, 30); var odate=new date(); if(odate.gettime()-obj.lastmove>30) { domove(obj, json, fnend); } } function getstyle(obj, attr) { if(obj.currentstyle) { return obj.currentstyle[attr]; } else { return getcomputedstyle(obj, false)[attr]; } } function domove(obj, json, fnend) { var icur=0; var attr=''; var bstop=true; //假设运动已经该停止了 for(attr in json) { if(attr=='opacity') { icur=parseint(100*parsefloat(getstyle(obj, 'opacity'))); } else { icur=parseint(getstyle(obj, attr)); } if(isnan(icur)) { icur=0; } var ispeed=(json[attr]-icur)/8; ispeed=ispeed>0?math.ceil(ispeed):math.floor(ispeed); if(parseint(json[attr])!=icur) { bstop=false; } if(attr=='opacity') { obj.style.filter="alpha(opacity:"+(icur+ispeed)+")"; obj.style.opacity=(icur+ispeed)/100; } else { obj.style[attr]=icur+ispeed+'px'; } } if(bstop) { clearinterval(obj.timer); obj.timer=null; if(fnend) { fnend(); } } obj.lastmove=(new date()).gettime(); }