欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript制作loading動(dòng)畫效果 loading效果

 更新時(shí)間:2014年01月14日 16:02:58   作者:  
項(xiàng)目中多處要給ajax提交的時(shí)候增加等待動(dòng)畫效果,所以就寫了一個(gè)簡(jiǎn)單的通用js方法,大家參考使用吧

復(fù)制代碼 代碼如下:

/*ajax提交的延時(shí)等待效果*/

var AjaxLoding = new Object();

//wraperid : 顯示loding圖片的容器元素
//ms:表示loding圖標(biāo)顯示的時(shí)長(zhǎng),毫秒
//envent:表示出發(fā)事件的事件源對(duì)象,用于獲得出發(fā)事件的對(duì)象
//callback:表示動(dòng)畫結(jié)束后執(zhí)行的回掉方法
//stop()方法表示在回掉方法執(zhí)行成功后執(zhí)行的隱藏動(dòng)畫的操作
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; //顯示loding圖標(biāo)的parent元素
    this.obj = $("#" + this.lodingid);
    this.sourceEventElement=$(event.currentTarget);
    this.start = function () {
      this.obj.css({positin:"relative"});
        this.sourceEventElement.attr("disabled",true);
        //默認(rèn)將圖標(biāo)居中與lodingid顯示,設(shè)置如下樣式
        var imgobj = $("<img src='/images/loaderc.gif' style='position:absolute; width:32px; height:32px;' id='img_loding'/>");
        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);
    }
};



調(diào)用方法:

復(fù)制代碼 代碼如下:

$("#elementid").click(function (e) {
  var obj = new AjaxLoding.load("div_test", 2000,e,0,0,function () {
            //alert("提交成功!");
            obj.stop();//隱藏加載圖標(biāo)
        });
  obj.start();
        });

這是我用的loding圖標(biāo),大家可以自行替換。

相關(guān)文章

最新評(píng)論