js代码
主要处理函数
function getStyle(obj,name){ if(obj.currentStyle) { return obj.currentStyle[name]; } else { return getComputedStyle(obj,false)[name]; }}function Running(obj,json,fnEnd){ clearInterval(obj.timer); obj.timer=setInterval(function() { var now=0; var bStop=true; for (var attr in json) { if(attr=='opacity') { now=Math.round(parseFloat(getStyle(obj,attr))*100); } else { now=parseInt(getStyle(obj,attr)); document.getElementById('wenzi').value=attr; } var speed=(json[attr]-now)/5; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(now!=json[attr])bStop=false; if(attr=='opacity') { obj.style.filter='alpha(opacity:'+now+speed+')'; obj.style.opacity=(now+speed)/100; } else { obj.style[attr]=speed+now+'px'; } } if(bStop) { clearInterval(obj.timer); if(fnEnd)fnEnd(); } }, 30);}function Flexing(obj,json,fnEnd){ clearInterval(obj.timer); obj.timer=setInterval(function() { var now=0; var bStop=true; for (var attr in json) { if(!obj.speed)obj.speed={}; if(!obj.speed[attr])obj.speed[attr]=0; now=parseInt(getStyle(obj,attr)); if(Math.abs(json[attr]-now)>1 || Math.abs(obj.speed[attr])>1) { bStop=false; obj.speed[attr]+=(json[attr]-now)/5; obj.speed[attr]*=0.85; var MaxSpeed=50; if(Math.abs(obj.speed[attr])>MaxSpeed) { obj.speed[attr]=obj.speed[attr]>0?MaxSpeed:-MaxSpeed; } obj.style[attr]=now+obj.speed[attr]+'px'; } } if(bStop) { clearInterval(obj.timer); obj.style[attr]=json[attr]+'px'; if(fnEnd)fnEnd(); } }, 30);}
body部分内容
样式