JQuery+Bootstrap 自定義全屏Loading插件的示例demo
JQuery+Bootstrap 自定義全屏Loading插件
/** * 自定義Loading插件 * @param {Object} config * { * content[加載顯示文本], * time[自動關(guān)閉等待時間(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); } }
基本調(diào)用:
var loading = new KZ_Loading('數(shù)據(jù)加載中。。。'); setTimeout(function () { console.log('加載完成!'); loading.hide(); }, 1000);
自動關(guān)閉:
var loading = new KZ_Loading({ content: '數(shù)據(jù)加載中。。。', time: 2000 }); loading.show();
銷毀Loading Dom節(jié)點:
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>
總結(jié)
以上所述是小編給大家介紹的JQuery+Bootstrap 自定義全屏Loading插件的示例demo,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
- bootstrap可編輯下拉框jquery.editable-select
- bootstrap+jQuery 實現(xiàn)下拉菜單中復選框全選和全不選效果
- Spring shiro + bootstrap + jquery.validate 實現(xiàn)登錄、注冊功能
- bootstrap+jQuery實現(xiàn)的動態(tài)進度條功能示例
- vue中如何引入jQuery和Bootstrap
- Bootstrap jquery.twbsPagination.js動態(tài)頁碼分頁實例代碼
- jQuery簡單實現(xiàn)提交數(shù)據(jù)出現(xiàn)loading進度條的方法
- jquery顯示loading圖片直到網(wǎng)頁加載完成的方法
- 基于jquery的loading 加載提示效果實現(xiàn)代碼
- 基于jquery的loading效果實現(xiàn)代碼
相關(guān)文章
jQuery Tab插件 用于在Tab中顯示iframe,附源碼和詳細說明
最近有個需求,需要在Tab中放置iFrame,于是做了一個jQuery的Tab插件。2011-06-06jQuery結(jié)合CSS制作漂亮的select下拉菜單
對于我來說,標準的HTML元素(Select)已經(jīng)讓我感到討厭。它不能夠正常的在IE瀏覽器上顯示。還有一點就是他并不僅僅包含簡單的文本。本實例將完全摒棄select元素,通過JQuery和CSS來構(gòu)建DropDown元素。2015-05-05jQuery將多條數(shù)據(jù)插入模態(tài)框的示例代碼
這篇文章主要介紹了使用jQuery將多條數(shù)據(jù)插入模態(tài)框的方法,很簡單,很實用,需要的朋友可以參考下2014-09-09