您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JS封装运动框架的一种写法

2024/3/2 1:24:58发布15次查看
function animate(obj, json, interval, sp, fn) { clearinterval(obj.timer); //var k = 0; //var j = 0; function getstyle(obj, arr) { if(obj.currentstyle){ return obj.currentstyle[arr]; //针对ie } else { return document.defaultview.getcomputedstyle(obj, null)[arr]; } } obj.timer = setinterval(function(){ //j ++; var flag = true; for(var arr in json) { var icur = 0; //k++; if(arr == "opacity") { icur = math.round(parsefloat(getstyle(obj, arr))*100); } else { icur = parseint(getstyle(obj, arr)); } var speed = (json[arr] - icur) * sp; speed = speed > 0 ? math.ceil(speed): math.floor(speed); if(icur != json[arr]){ flag = false; } if(arr == "opacity"){ obj.style.filter = "alpha(opacity : '+(icur + speed)+' )"; obj.style.opacity = (icur + speed)/100; }else { obj.style[arr] = icur + speed + "px"; } //console.log(j + "," + arr +":"+ flag); } if(flag){ clearinterval(obj.timer); //console.log(j + ":" + flag); //console.log("k = " + k); //console.log("j = " + j); //console.log("done"); if(fn){ fn(); } } },interval); }
以上就是js封装运动框架的一种写法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product