Home  >  Article  >  Web Front-end  >  javascript universal loading animation effect example code_javascript skills

javascript universal loading animation effect example code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:03:551440browse

Since many places in the project need to add waiting animation effects when submitting ajax, I wrote a simple general js method;
The code is as follows:

Copy code The code is as follows:

/*Delay waiting effect of ajax submission*/

var AjaxLoding = new Object();

//wraperid: Container element that displays the loding image
//ms: Indicates the duration of the loding icon display, milliseconds
//envent: Represents the event source object of the launching event, used to obtain the object of the launching event
//callback: Indicates the callback method executed after the animation ends
//stop() method indicates the operation of hiding the animation executed after the callback 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);
//Default will The icon is centered and displayed with lodingid. Set the following style
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();
       }); sourceEventElement.attr("disabled", false);
}
};



Calling method:


Copy code

The code is as follows:$("#elementid" ).click(function (e) { var obj = new AjaxLoding.load("div_test", 2000,e,0,0,function () {
                                                                                                                                    
                                                                                                                                                                                    

The loding icon I used can be replaced by you;

The implementation is very simple, without considering performance, standards, etc.; there are still many imperfections, and better communication is welcome;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn