标签:
function funStyle(obj,attr)
{
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,false)[attr];
}
function funStartMove(obj,json,fnFinish,time)
{
funStopMove(obj);
funMove(obj,json,fnFinish);
obj.timer = setInterval(function(){
funMove(obj,json,fnFinish);
},time);
}
function funStopMove(obj)
{
clearInterval(obj.timer);
}
function funMove(obj,json,fnFinish)
{
obj.bStop = true;
for (var attr in json) {
funPartMove(obj,attr,json[attr]);
}
if (obj.bStop) {
funStopMove(obj);
if (fnFinish) fnFinish();
}
}
function funPartMove(obj,attr,iTarget)
{
if (attr=="opacity") {
obj.myValue = Math.round(parseFloat(funStyle(obj,attr))*100);
}else{
obj.myValue = parseInt(funStyle(obj,attr));
}
if (obj.myValue!=iTarget) {
// 匀速运动
obj.iSpeed = obj.myValue<iTarget?1:-1;
//缓冲运动
// obj.iSpeed = (iTarget-obj.myValue)/30;
// obj.iSpeed =obj.iSpeed>0?Math.ceil(obj.iSpeed):Math.floor(obj.iSpeed);
obj.myValue += obj.iSpeed;
if (attr=="opacity") {
obj.style.filter = "alpha(opacity:"+obj.myValue+")";
obj.style.opacity = obj.myValue*0.01;
}else{
obj.style[attr] = obj.myValue+"px";
}
if (obj.myValue!=iTarget) obj.bStop = false;
}
}
标签:
原文地址:http://www.cnblogs.com/WeWeZhang/p/5757770.html