完美运动框架

 1 /**
 2  * Created by linxd on 2015/6/6.
 3  */
 4 
 5 
 6 function getStyle(obj, name) {
 7     if (getComputedStyle) {
 8         return getComputedStyle(obj, null)[name];
 9     } else {
10         return obj.currentStyle[name];
11     }
12 }
13 
14 function startMove(obj, json, fnEnd) {
15     clearInterval(obj.timer);
16     obj.timer=setInterval(function () {
17         var bStop = true;
18         for (var attr in json) {
19             var cur = 0;
20             if (attr == "opacity") {
21                 cur = Math.round(parseFloat(getStyle(obj, attr))*100);
22             } else {
23                 cur = parseInt(getStyle(obj, attr));
24             }
25             var speed = (json[attr]-cur)/6;
26 
27             speed=speed>0? Math.ceil(speed):Math.floor(speed);
28 
29             if (cur != json[attr]) {
30                 bStop = false;
31             }
32 
33             if (attr == "opacity") {
34                 obj.style.filter = "alpha(opacity:" + (cur+speed) + ")";
35                 obj.style.opacity = (cur+speed)/100;
36             } else {
37                 obj.style[attr] = cur + speed + "px";
38             }
39         }
40 
41         if (bStop) {
42             clearInterval(obj.timer);
43             if (fnEnd) fnEnd();
44         }
45     }, 30);
46 }

http://bbs.zhinengshe.com/thread-1198-1-1.html

原文地址:https://www.cnblogs.com/linxd/p/4558520.html