码迷,mamicode.com
首页 > Web开发 > 详细

JS运动库

时间:2014-07-22 00:29:36      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:style   blog   java   color   io   art   

 1 // JavaScript Document
 2 
 3 function startMove(obj,json,endFn){
 4     
 5         clearInterval(obj.timer);
 6         
 7         obj.timer = setInterval(function(){
 8             
 9             var bBtn = true;
10             
11             for(var attr in json){
12                 
13                 var iCur = 0;
14             
15                 if(attr == ‘opacity‘){
16                     if(Math.round(parseFloat(getStyle(obj,attr))*100)==0){
17                     iCur = Math.round(parseFloat(getStyle(obj,attr))*100);
18                     
19                     }
20                     else{
21                         iCur = Math.round(parseFloat(getStyle(obj,attr))*100) || 100;
22                     }    
23                 }
24                 else{
25                     iCur = parseInt(getStyle(obj,attr)) || 0;
26                 }
27                 
28                 var iSpeed = (json[attr] - iCur)/8;
29             iSpeed = iSpeed >0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
30                 if(iCur!=json[attr]){
31                     bBtn = false;
32                 }
33                 
34                 if(attr == ‘opacity‘){
35                     obj.style.filter = ‘alpha(opacity=‘ +(iCur + iSpeed)+ ‘)‘;
36                     obj.style.opacity = (iCur + iSpeed)/100;
37                     
38                 }
39                 else{
40                     obj.style[attr] = iCur + iSpeed + ‘px‘;
41                 }
42                 
43                 
44             }
45             
46             if(bBtn){
47                 clearInterval(obj.timer);
48                 
49                 if(endFn){
50                     endFn.call(obj);
51                 }
52             }
53             
54         },30);
55     
56     }
57     
58     
59     function getStyle(obj,attr){
60         if(obj.currentStyle){
61             return obj.currentStyle[attr];
62         }
63         else{
64             return getComputedStyle(obj,false)[attr];
65         }
66     }
67     
68     function stopMove(obj){
69         clearInterval(obj.timer);
70     }

JS运动库,布布扣,bubuko.com

JS运动库

标签:style   blog   java   color   io   art   

原文地址:http://www.cnblogs.com/reeoo/p/3858035.html

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