js--鏈式緩衝運動架構

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   sp   for   strong   on   

這些架構都是鄙人自學的網上視頻,至於是哪家,想必大家都知道的,當然不糾結這個,最主要的是學習的過程和結果,甚至於你理解,掌握了沒有

網上有很多的開源架構,很佩服他們的思路和寫法,或許這就是代碼之美吧

我一個小小的前台,做介面的,現在也要去學習設計思路了,畢竟你拿工資的多少和你掌握技能的多少、深度是成正比的

當然更要相信  

努力必有回報,堅持一定成功

 

以下是更新的學習運動架構的進度和代碼

 

 

更新時間:2014-12-11

js架構---緩衝鏈式運動--已經掌握

 

 

 1     //運動架構 2     //author:Nomand 3     //2014-12-11 4     //相容各中核心瀏覽器 5     //解決了webkit核心下的瀏覽器小數的問題 6     function getStyle(obj,attr){ 7         return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,false)[attr]; 8     } 9     function startMove(obj,attr,iTarget,fn){10         clearInterval(obj.time);11         var iCur = 0;12         obj.time=setInterval(function() {13             attr == ‘opacity‘ ? iCur = parseInt(parseFloat(getStyle(obj, attr)) * 100) : iCur = parseInt(getStyle(obj, attr));14             var speed = (iTarget - iCur) / 8;15             speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);16             if (iCur == iTarget) {17                 clearInterval(obj.time);18                 if(fn) {19                     fn();20                 }21             } else {if(obj.style.opacity == (iCur + speed) / 100){22                         iCur +=1;23                     }24                 //這裡是解決在webkit下小數問題,當瀏覽器認為他到達的時候事實上並沒有到達,這裡直接給他加上125                 if(obj.style.opacity == (iCur + speed) / 100){26                     iCur +=1;27                 }28                 attr == ‘opacity‘ ? obj.style.opacity = (iCur + speed) / 100 : obj.style[attr] = iCur + speed + "px";29             }30         },20)31     }

 js架構--完美運動(尚未掌握),需要仔細學習

 1 function startMove(obj, json, fnEnd) 2 { 3     if(obj.timer) 4     { 5         clearInterval(obj.timer); 6     } 7     obj.timer=setInterval(function (){ 8         doMove(obj, json, fnEnd); 9     }, 30);10     11     var oDate=new Date();12     13     if(oDate.getTime()-obj.lastMove>30)14     {15         doMove(obj, json, fnEnd);16     }17 }18 19 function getStyle(obj, attr)20 {21     if(obj.currentStyle)22     {23         return obj.currentStyle[attr];24     }25     else26     {27         return getComputedStyle(obj, false)[attr];28     }29 }30 31 function doMove(obj, json, fnEnd)32 {33     var iCur=0;34     var attr=‘‘;35     var bStop=true;    //假設運動已經該停止了36     37     for(attr in json)38     {39         if(attr==‘opacity‘)40         {41             iCur=parseInt(100*parseFloat(getStyle(obj, ‘opacity‘)));42         }43         else44         {45             iCur=parseInt(getStyle(obj, attr));46         }47         48         if(isNaN(iCur))49         {50             iCur=0;51         }52         53         var iSpeed=(json[attr]-iCur)/8;54         iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);55         56         if(parseInt(json[attr])!=iCur)57         {58             bStop=false;59         }60         61         if(attr==‘opacity‘)62         {63             obj.style.filter="alpha(opacity:"+(iCur+iSpeed)+")";64             obj.style.opacity=(iCur+iSpeed)/100;65         }66         else67         {68             obj.style[attr]=iCur+iSpeed+‘px‘;69         }70     }71     72     if(bStop)73     {74         clearInterval(obj.timer);75         obj.timer=null;76         77         if(fnEnd)78         {79             fnEnd();80         }81     }82     83     obj.lastMove=(new Date()).getTime();84 }

 

js--鏈式緩衝運動架構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.