jQuery擴張實現DOM對象屬性同步動態效果

 //-----------動態效果函數封裝

  

   jQuery.fn.extend({

                  move:  function(attrs, t ,fn){

                                  var attrs=[],

                                        len=this.length,

                                        json={},

                                        i, timer=null;

                             len ||  typeof this ==='object' ||  jQuery.type(this) == 'array' && return false; 

                             var m = t && 2000;                                

                              for(; i<len; i++){

                                        move.applay(jQuery(this[i]),attrs,t);

                               }

                              for(var attr in attrs) {

                                    var s;

                                     json[attr]={};

                                     s=parseFloat(jQuery(this).getAttribute(attr));

                                     json[attr].a=s

                                     json[attr].b=parseFloat(attrs[attr])-s;

                                     json[attr].t=m;                            

                              }

                             clearInterval(this.timer);

                             var start=+new Date();

                             this.timer=setInterval(function () {

                                    var now =+new Date() - start;

                                     if(now>=m){

                                              now=m;

                                              clearInterval(this.timer);

                                              }

                                               for(attr in attrs){

                                                    json[attr].c=now;

                                                    var value=json[attr].a+json[attr].b*json[attr].c/m;

                                                    jQuery(this).css(attr,value);

                                                }

                             },30)

                             fn && fn();

                 }

})

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章