zoukankan      html  css  js  c++  java
  • 运动框架

    完美运动框架

     1 function getStyle(obj,attr)
     2 {
     3     if(obj.currentStyle)
     4     {
     5         return obj.currentStyle[attr];
     6     }
     7     else
     8     {
     9         return getComputedStyle(obj,false)[attr];
    10     }
    11 }
    12 
    13 function move(obj,json,fn)
    14 {
    15     clearInterval(obj.timer);
    16     obj.timer=setInterval(function(){
    17     var dd=true;
    18     for(var attr in json)
    19     {
    20         var current=0;
    21         if(attr=='opacity')
    22         {
    23             current=parseInt(parseFloat(getStyle(obj,attr))*100);
    24         }
    25         else
    26         {
    27             current=parseInt(getStyle(obj,attr));
    28         }
    29     
    30     
    31         speed=(json[attr]-current)/8;
    32         speed=speed>0?Math.ceil(speed):Math.floor(speed);
    33         
    34         if(current!=json[attr])
    35         {
    36             dd=false;
    37         }
    38         
    39 
    40         
    41             if(attr=='opacity')
    42             {
    43                 obj.style.filter='alpha(opacity:'+(current+speed)+')';
    44                 obj.style.opacity=(current+speed)/100;
    45             }
    46             else
    47             {
    48             obj.style[attr]=current+speed+'px';
    49             }
    50                     
    51     }
    52     
    53             if(dd)
    54             {
    55                 clearInterval(obj.timer);
    56                 if(fn)
    57                 {
    58                     fn();
    59                 }
    60                 
    61             }
    62     },30);
    63 }
    目标很遥远,但是如果你拼了命努力,即使到最后没有达到目标,但是你会发现,在某种程度上你已经成功了。
  • 相关阅读:
    python 函数2
    python 函数
    python 中string格式化
    python中的集合
    值&&引用传递&&序列化
    线程&&进程
    c#委托
    .net框架介绍
    类的定义
    ef中关于数据库中int为null问题
  • 原文地址:https://www.cnblogs.com/Cavalary/p/8005049.html
Copyright © 2011-2022 走看看