1 /*2 * 3 * 2015/4/184 * JS Basics and Tools Library5 * 6 * 7 * */8 //Get Object Styles9 functionHgetstyle (obj, attr) {Ten returnOBJ.CURRENTSTYLE?OBJ.CURRENTSTYLE[ATTR]: getComputedStyle (obj,NULL) [attr]; One } A - //Move function - functionhdomove (obj, attr, S, Target, ENDFN) { the //gets the position of the current object - varpos =parseint (Hgetstyle (obj,attr)); - //if the position of the target point is greater than the current distance, then it is the positive move, or the negative move -s = target > pos? S:-s; + //Clear Previous Timer - clearinterval (obj.hdomovetimer); + //Create a new timer AObj.hdomovetimer = SetInterval (function(){ at //distance is equal to the current object's live distance + distance to be moved each time - varDistance = parseint (Hgetstyle (obj,attr)) +s; - //if the distance calculated in the previous step is greater than the distance of the given target point, the correction = target distance - if(Distance > Target && s > 0 | | Distance < target && S < 0){ -Distance =Target; - } in //Object Move -OBJ.STYLE[ATTR] = distance + ' px '; to //if the distance has reached the target point, clear the timer, execute the callback function + if(Distance = = =target) { - clearinterval (obj.hdomovetimer); the //is the callback function undefined? Do not execute the *ENDFN &&ENDFN (); $ }Panax Notoginseng},20) - } the //jitter Function + functionhshake (obj, attr, ENDFN) { A /* the * Two ways to solve the problem of jitter function hidden trouble: + * 1. Enter function advanced to an if control, never directly executes the body code of the Jitter function, but takes the position of the current object and the position after 50 milliseconds, compares equality, if equal, - * Indicates that the object's current jitter is over and can perform a jitter effect! (with a little bit of bug) $ * 2. It is good to use a variable switch to control it, but the variable switch cannot be initialized or cleared after the function ends. Otherwise, each time this function is triggered, you can $ * Smooth down execution of the body code of the Jitter function, it will not fix the problem. Need a variable, he can exist longer, the variable is hung on the body of window (win - * Dow.flag = False), each time can only trigger the object to jitter, the next need to wait until the last jitter of the object jitter after the end of the jitter, this effect is not intended to - *, so, the switch is hung in the transmission of the obj body is the best choice, each object on the body of the switch to manage their own jitter problem processing, and obj.flag at the end of the function execution the * is not recycled, because, he is passed in from outside the function, life is very long!! So when the function is triggered again, Obj.flag = True, this condition is set if (Obj.flag) - * {return}, do not go down ... Until the end of the jitter, num = = = The last value of the array, then the value is assigned to False.Wuyi * */ the if(Obj.flag) {return} ;//initialization is undefined (false does not execute return), -Obj.flag =true;//immediately assigns a value of true, so that the second trigger function is True (Obj.flag is the property of the passed in object, and the object is transmitted from the outside, so it is not recycled), directly return, do not execute the following code. Wu - varpos = parseint (Hgetstyle (obj, attr));//the location of the first object About $ //jitter function Motion Track array - vararr = [];//20,-20, 18,-18 ..... 0 - varnum = 0; - varTimer =NULL; A //automatically generate an array of motion trajectories + for(vari=20; i>0; i-=2 ) { theArr.push (I,-i); - } $Arr.push (0); the //Clear the timer first the clearinterval (obj.shake); the theObj.shake = SetInterval (function (){ -OBJ.STYLE[ATTR] = pos + arr[num] + ' px '; innum++; the //If you have moved to the last value, clear the timer, execute the callback function the if(num = =arr.length) { About clearinterval (obj.shake); theENDFN &&ENDFN (); theObj.flag =false;//after the jitter is over, the assignment is false, the function is triggered again, the top judgment will be executed, and the pull will be shaken again . the } +}, 50); - } the Bayi the /* the read or set the transparent value of El element, Val value is 0-1 - */ - functionhopacity (el,val) { the varf=el.filters,s=El.style; the if(arguments.length==1) the returnF? (F.alpha?) (f.alpha.opacity/100): 1):(s.opacity| | 1); theS.zoom=1; -S.filter= "Alpha (opacity=" +parseint (val*100) + ")"; thes.opacity=Val; the }; the 94 //transparency fade out function the functionhfadeout (obj, time, ENDFN) { theObj.inum = 0; the clearinterval (obj.hfadetimer);98Obj.hfadetimer = SetInterval (function(){ Aboutobj.inum++; - //using the set and read transparency functions101Hopacity (obj,hopacity (obj)-0.1);102 //dealing with some browser opacity cannot go to zero issues. 103 if(Obj.inum >= 10){104obj.style.opacity = 0; theObj.inum = 0;106 }107 if(Hgetstyle (obj, ' opacity ') = = 0){108 clearinterval (obj.hfadetimer);109ENDFN &&ENDFN (); the }111 },time) the }113 the the //gets the current and sets the detail date, sets the second parameter to determine the date and year details of the obtained year and month the functionHgettime (iNum) {117 varHtime ={};118 119 varMyTime =NewDate (); - 121 varIyear =mytime.getfullyear ();122 varImonth = Mytime.getmonth () +1;123 varIDate =mytime.getdate ();124 varIweek =Mytime.getday (); the varIhours =mytime.gethours ();126 varImin =mytime.getminutes ();127 varISec =mytime.getseconds (); - 129 if(Iweek = = = 0) Iweek = ' Sunday '; the if(Iweek = = = 1) iweek = ' Monday ';131 if(Iweek = = = 2) Iweek = ' Tuesday '; the if(Iweek = = = 3) Iweek = ' Wednesday ';133 if(Iweek = = = 4) Iweek = ' Thursday ';134 if(Iweek = = = 5) Iweek = ' Friday ';135 if(Iweek = = = 6) Iweek = ' Saturday ';136 137 //The default display of all the month and day of the week and other detailed information138 if(INum = = 0 | |typeof(iNum) = = ' undefined '){139Htime.str = iyear+ ' +imonth+ ' month ' +idate+ ' Day ' +iweek+ ' + totwo (ihours) + ': ' + totwo (imin) + ': ' +Totwo (ISEC); $}Else if(INum = = 1){141Htime.str = Totwo (ihours) + ': ' + totwo (imin) + ': ' +Totwo (ISEC);142}Else if(INum = = 2){143Htime.str = Totwo (ihours) +totwo (imin) +Totwo (ISEC);144 }145 146 functiontotwo (n) {147 returnN < 10? ' 0 ' + N: ' +N;148 }149 //time Stamp MaxHtime.gettime = Math.floor (Mytime.gettime ()/1000);151Htime.hours =ihours; theHtime.min =Imin;153Htime.sec =ISec;154 returnhtime;155}
JS Basics and Tools Library