As a novice to native JavaScript, the learning of some widgets can consolidate knowledge and improve business efficiency;
Get the Element class:
var get={};
Get.$=function (ID) {
return getElementById (ID);
},
Get.$$=function (Oparent,sclass) {
var a=[];
var reclass=regexp ("(^|)" +sclass+ "(|$)");
var aelem=this.$$$ (oparent, "*");
for (Var i=0;i<aelem.length;i++) reclass.test (aelem[i].classname) && A.push (Aelem[i]);
return A;
},
Get.$$$=function (Obj,elem) {
Return (obj| | Document). getElementsByTagName (Elem);
}
Directional fixed speed Movement
Get the calculated style function:
function GetStyle (obj,attr) {
Return Obj.currentstyle?obj.currentstyle[attr]:window.getcomputedstyle (Obj,null) [attr];
}
Directed fixed-speed fixed-point callback function:
function Domove (OBJ,ATTR,SPE,S,ENDFN) {
Clearinterval (Obj.timer);
Spe= (parseint (GetStyle (obj,attr)) <s) spe:-spe;//If the current position is less than the target position, move in the positive direction (for example, top and right), and vice versa
Obj.timer=setinterval (function () {
var nows=parseint (GetStyle (obj,attr)) +spe;//pay attention First and then judge!
if (spe>0 && nows>=s | | spe<0 && nows<=s)
{
obj.style[attr]=s+ "px";
Clearinterval (Obj.timer);
ENDFN && ENDFN ();
}else{
obj.style[attr]=nows+ "px";
}
},20);
}
Explore JavaScript----Widget Backlog