国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JQuery+Bootstrap 自定義全屏Loading插件的示例demo

2024-05-06 15:37:14
字體:
來源:轉載
供稿:網友

JQuery+Bootstrap 自定義全屏Loading插件

/** * 自定義Loading插件 * @param {Object} config * { * content[加載顯示文本], * time[自動關閉等待時間(ms)] * }  * @param {String} config  * 加載顯示文本 * @refer 依賴 JQuery-1.9.1及以上、Bootstrap-3.3.7及以上 * @return {KZ_Loading} 對象實例 */function KZ_Loading(config) {  if (this instanceof KZ_Loading) {    const domTemplate = '<div class="modal fade kz-loading" data-kzid="@@KZ_Loadin_ID@@" backdrop="static" keyboard="false"><div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px"><div class="progress progress-striped active" style="margin-bottom: 0;"><div class="progress-bar" style="width: 100%;"></div></div><h5>@@KZ_Loading_Text@@</h5></div></div>';    this.config = {      content: 'loading...',      time: 0,    };    if (config != null) {      if (typeof config === 'string') {        this.config = Object.assign(this.config, {          content: config        });      } else if (typeof config === 'object') {        this.config = Object.assign(this.config, config);      }    }    this.id = new Date().getTime().toString();    this.state = 'hide';    /*顯示 */    this.show = function () {      $('.kz-loading[data-kzid=' + this.id + ']').modal({        backdrop: 'static',        keyboard: false      });      this.state = 'show';      if (this.config.time > 0) {        var that = this;        setTimeout(function () {          that.hide();        }, this.config.time);      }    };    /*隱藏 */    this.hide = function (callback) {      $('.kz-loading[data-kzid=' + this.id + ']').modal('hide');      this.state = 'hide';      if (callback) {        callback();      }    };    /*銷毀dom */    this.destroy = function () {      var that = this;      this.hide(function () {        var node = $('.kz-loading[data-kzid=' + that.id + ']');        node.next().remove();        node.remove();        that.show = function () {          throw new Error('對象已銷毀!');        };        that.hide = function () {};        that.destroy = function () {};      });    }    var domHtml = domTemplate.replace('@@KZ_Loadin_ID@@', this.id).replace('@@KZ_Loading_Text@@', this.config.content);    $('body').append(domHtml);  } else {    return new KZ_Loading(config);  }}

基本調用:

var loading = new KZ_Loading('數據加載中。。。');setTimeout(function () {  console.log('加載完成!');  loading.hide();}, 1000);

自動關閉:

var loading = new KZ_Loading({  content: '數據加載中。。。',  time: 2000});loading.show();

銷毀Loading Dom節點:

 loading.destroy();

ps:下面看下基于JQUERY BOOTSTRAP 最簡單的loading遮罩層

<%--loading遮罩層--%><div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">    <div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">      <div class="progress progress-striped active" style="margin-bottom: 0;">        <div class="progress-bar" style="width: 100%;"></div>      </div>      <h5 id="loadText">loading...</h5>    </div></div><%--loading方法--%><script type="text/javascript">  var loadingTime= 5;//默認遮罩時間  showLoading = function (loadText) {    if(!loadText){      $("#loadText").html(loadText)    }    $('#loadingModal').modal({backdrop: 'static', keyboard: false});  }  hideLoading = function () {    $('#loadingModal').modal('hide');  }</script>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 澄城县| 婺源县| 弋阳县| 凤城市| 长白| 古浪县| 来宾市| 诸暨市| 理塘县| 南投县| 远安县| 遵义市| 阳春市| 台中市| 黄陵县| 公安县| 东丰县| 卫辉市| 新巴尔虎右旗| 时尚| 湟中县| 绥滨县| 上饶市| 大城县| 泗洪县| 西畴县| 舟山市| 大英县| 平罗县| 陕西省| 龙游县| 滨海县| 墨玉县| 翁源县| 修武县| 昌宁县| 子长县| 库尔勒市| 扎鲁特旗| 威信县| 阆中市|