Javascript-based loading animation effect-loading effect-javascript skills

Source: Internet
Author: User
In the project, we need to add the waiting animation effect when submitting the ajax request. Therefore, we have written a simple general js method. For details, refer to and use it. The Code is as follows:


/* Latency wait result of ajax submission */

Var AjaxLoding = new Object ();

// Wraperid: Container element for displaying loding Images
// Ms: The length of time displayed by the loding icon, in milliseconds
// Envent: indicates the event source object of the departure event. It is used to obtain the object of the departure event.
// Callback: indicates the method for executing the callback after the animation ends.
// The stop () method indicates the operation of hiding an animation after the method is successfully executed.
AjaxLoding. load = function (lodingid, MS, event, left, top, callback ){

If (! Left | typeof left = undefined)
Left = 0;
If (! Top | typeof top = undefined)
Top = 0;

This. lodingid = lodingid; // display the parent element of the loding icon
This. obj = $ ("#" + this. lodingid );
This. sourceEventElement = $ (event. currentTarget );
This. start = function (){
This.obj.css ({positin: "relative "});
This. sourceEventElement. attr ("disabled", true );
// By default, the icon is centered and the lodingid is displayed. The following style is set:
Var imgobj = $ ("");
Imgobj.css ({left: this. obj. width ()/2-imgobj.width ()/2-left, top: this. obj. height ()/2-imgobj.height ()/2-top });
Imgobj. appendTo (this. obj );
This. obj. animate ({height: this. obj. height ()}, MS, function (){
Callback ();
});
};
This. stop = function (){
$ ("# Img_loding"). remove ();
This. sourceEventElement. attr ("disabled", false );
}
};



Call method:

The Code is as follows:


$ ("# Elementid"). click (function (e ){
Var obj = new AjaxLoding. load ("p_test", 2000, e, function (){
// Alert ("submitted successfully! ");
Obj. stop (); // hide the loading icon
});
Obj. start ();
});

This is the loding icon I used. You can replace it by yourself.

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.