Explore JavaScript----Widget Backlog

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.