輕量級網頁遮罩層jQuery外掛程式用法執行個體,遮罩jquery執行個體

來源:互聯網
上載者:User

輕量級網頁遮罩層jQuery外掛程式用法執行個體,遮罩jquery執行個體

本文執行個體講述了輕量級網頁遮罩層jQuery外掛程式用法。分享給大家供大家參考。具體如下:

使用jQuery的好處是很多人為它寫一些組件,而在項目所需用到功能也都可以找到一些組件去完成。

現在又這樣一個需求當使用者點擊一個按鈕後不允許使用者進行任何的操作,取而代之的是彈出一個遮罩層顯示一個loading提示框,效果如下。

其實這個需求很簡單,但很多組件體積相對這個需求來說太大了,在網上瞎溜達了找到了一個還不錯的組件,作者是上面也沒有寫。現在就來分析一下這個組件的源碼和使用

/** * @部分參數說明 */(function($){ $.fn.extend({  //主函數  toggleLoading: function(options){      // 找到遮罩層    var crust = this.children(".x-loading-wanghe");      // 當前操作的元素      var thisjQuery = this;      // 實現toogle(切換遮罩層出現與消失)效果的判斷方法    if(crust.length>0){      if(crust.is(":visible")){        crust.fadeOut(500);      }else{        crust.fadeIn(500);      }      return this;    }   // 擴充參數   var op = $.extend({    z: 9999,    msg:'資料載入中...',    iconUrl:'images/loading.gif',    width:18,    height:18,    borderColor:'#6bc4f5',    opacity:0.5,        agentW:thisjQuery.outerWidth(),        agentH:thisjQuery.outerHeight()   },options);   if(thisjQuery.css("position")=="static")     thisjQuery.css("position","relative");   //var w = thisjQuery.outerWidth(),h = thisjQuery.outerHeight();   var w = op.agentW,h = op.agentH;   crust = $("<div></div>").css({//外殼    'position': 'absolute',    'z-index': op.z,    'display':'none',    'width':w+'px',    'height':h+'px',    'text-align':'center',    'top': '0px',    'left': '0px',    'font-family':'arial',    'font-size':'12px',    'font-weight':'500'   }).attr("class","x-loading-wanghe");   var mask = $("<div></div>").css({//蒙版    'position': 'absolute',    'z-index': op.z+1,    'width':'100%',    'height':'100%',    'background-color':'#333333',    'top': '0px',    'left': '0px',    'opacity':op.opacity   });   //71abc6,89d3f8,6bc4f5   var msgCrust = $("<span></span>").css({//訊息外殼      'position': 'relative',        'top': (h-30)/2+'px',      'z-index': op.z+2,      'height':'24px',      'display':'inline-block',      'background-color':'#cadbe6',      'padding':'2px',      'color':'#000000',      'border':'1px solid '+op.borderColor,      'text-align':'left',      'opacity':0.9     });   var msg = $("<span>"+op.msg+"</span>").css({//訊息主體       'position': 'relative',       'margin': '0px',      'z-index': op.z+3,      'line-height':'22px',      'height':'22px',      'display':'inline-block',      'background-color':'#efefef',      'padding-left':'25px',      'padding-right':'5px',      'border':'1px solid '+op.borderColor,      'text-align':'left',      'text-indent':'0'     });      var msgIcon = $("<img src="+op.iconUrl+" />").css({//表徵圖      'position': 'absolute',      'top': '3px',      'left':'3px',      'z-index': op.z+4,      'width':'18px',      'height':'18px'     });        // 拼裝遮罩層   msg.prepend(msgIcon);    msgCrust.prepend(msg);    crust.prepend(mask);    crust.prepend(msgCrust);   thisjQuery.prepend(crust);     // alert(thisjQuery.html());   crust.fadeIn(500);   //模態設定   return this;  } });})(jQuery);

相關配置

配置&configure


全部配置 預設值 說明
z: 9999 圖層z-index,當蒙版遮罩不住時候適當增大其值
msg: 資料載入中... 提示資訊
iconUrl: images/loading.gif 提示圖片url
height: 18 表徵圖預設高(px)
width: 18 表徵圖預設寬(px)
borderColor #6bc4f5 提示的邊框顏色
opacity: 0.5 蒙版的透明度
agentW: 當前元素的寬度 蒙版的寬度
agentH: 當前元素的高度 蒙版的高度


希望本文所述對大家的jquery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.