I am also a rookie, from the Internet search for a long time, sealed equipment note a set of motion framework, to strengthen everyone's understanding of this, hope that many proposals.
GetId:function(elemid) {returndocument.getElementById (elemid); }, GetStyle:function(obj,attr) {returnObj.currentstyle?obj.currentstyle[attr]:getcomputedstyle (obj,false) [attr]; }, Startmove:function(obj,json,fnend) {/*OBJ represents a collection of properties that require the movement of the object JSON, such as {' width ': +, ' height ': the function of the fnend motion at the end of the */ var_this = This; Clearinterval (Obj.timer); //if the object has motion, clear the timer firstObj.timer= SetInterval (function(){ varEstop =true;//indicates the motion of the object for(varattrinchJSON) { varStart = 0; if(attr = = ' opacity ') {//if it is a property of transparencyStart = Math.Round (Math.floor (_this.getstyle (obj,attr) *100)); }Else{Start=parseint (_this.getstyle (obj,attr)); } //if if(Start! =Json[attr]) {Estop=false; } //set the value of the speed varSpeed = (json[attr]-start)/6//if it is greater than 0, take the whole upward, otherwise it will be rounded down;Speed > 0?Math.ceil (Speed): Math.floor (speed); //if the change in transparency if(attr = = ' opacity ') {Obj.style.filter= ' Alpha (opacity: ' + (start + speed) + ') ';//Set IEObj.style.opacity = (start+ speed)/100; }Else{ //This is the other property in addition to transparencyOBJ.STYLE[ATTR] = start + speed + ' px '; } } //clears the timer if the motion reaches the target point if estop = = True if(estop) {clearinterval (Obj.timer); if(Fnend) fnend (); } },30) }
The above is my three methods of encapsulation:
Call the following
Elemmouse:function(){ var_this = This; varConphone = This. GetId (' Conphone '); This. addevent (Conphone, ' mouseover ',function() {_this.startmove (conphone,{' Width ': $, ' height ': 500,},function() {alert (' End of movement ') }) }) This. addevent (Conphone, ' mouseout ',function() {_this.startmove (conphone,{' Width ': +, ' height ': 50},function() {alert (' End of movement ') }) }) }
JS Motion Frame