星联网络专注帝国CMS二次功能插件开发-精品网站模板站长代码素材

  • 最近更新
  • 模板:33
  • 记录:12641|
  • 插件:52|
  • 工具:4|
  • 代码:8|
  • 评论:0

JQuery+Bootstrap 自定义全屏Loading插件

前言

本文重点解决JQuey+Boosap自定义全屏Loadig插件问题,希望能够帮助到你

 1 /**
 2  * 自定义Loading插件
 3  * @param {Object} config
 4  * {
 5  * content[加载显示文本],
 6  * time[自动关闭等待时间(ms)]
 7  * } 
 8  * @param {String} config 
 9  * 加载显示文本
10  * @refer 依赖 JQuery-1.9.1及以上、Bootstrap-3.3.7及以上
11  * @return {KZ_Loading} 对象实例
12  */
13 function KZ_Loading(config) {
14     if (this instanceof KZ_Loading) {
15         const domTemplate = '<div class="modal fade kz-loading" data-kzid="@@[email protected]@" 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>@@[email protected]@</h5></div></div>';
16         this.config = {
17             content: 'loading...',
18             time: 0,
19         };
20         if (config != null) {
21             if (typeof config === 'string') {
22                 this.config = Object.assign(this.config, {
23                     content: config
24                 });
25             } else if (typeof config === 'object') {
26                 this.config = Object.assign(this.config, config);
27             }
28         }
29         this.id = new Date().getTime().toString();
30         this.state = 'hide';
31 
32         /*显示 */
33         this.show = function () {
34             $('.kz-loading[data-kzid=' + this.id + ']').modal({
35                 backdrop: 'static',
36                 keyboard: false
37             });
38             this.state = 'show';
39             if (this.config.time > 0) {
40                 var that = this;
41                 setTimeout(function () {
42                     that.hide();
43                 }, this.config.time);
44             }
45         };
46         /*隐藏 */
47         this.hide = function (callback) {
48             $('.kz-loading[data-kzid=' + this.id + ']').modal('hide');
49             this.state = 'hide';
50             if (callback) {
51                 callback();
52             }
53         };
54         /*销毁dom */
55         this.destroy = function () {
56             var that = this;
57             this.hide(function () {
58                 var node = $('.kz-loading[data-kzid=' + that.id + ']');
59                 node.next().remove();
60                 node.remove();
61                 that.show = function () {
62                     throw new Error('对象已销毁!');
63                 };
64                 that.hide = function () {};
65                 that.destroy = function () {};
66             });
67         }
68 
69         var domHtml = domTemplate.replace('@@[email protected]@', this.id).replace('@@[email protected]@', this.config.content);
70         $('body').append(domHtml);
71     } else {
72         return new KZ_Loading(config);
73     }
74 }

本网刊登的文章均仅代表作者个人观点,并不代表本网立场。文中的论述和观点,敬请读者注意判断。

本文地址:http://www.xlkjgs.com/notes/js/1701.html

以上内容由本站整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

星联网络

星联网络是中国最具实战的互联网创业者的知识服务商,这里有互联网行业动态,网络推广,SEO优化,SEM优化,ESC配置,行业经验分型,互联网项目,微信营销、淘宝客赚钱、新媒体营销、京东运营、跨境电商等众多互联网营销知识分享

站长运营站长必备网站运营之道才能长久发展