码迷,mamicode.com
首页 > 其他好文 > 详细

完美运动框架

时间:2015-06-07 15:48:23      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

 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

完美运动框架

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!