JQuery+Bootstrap 自定义全屏Loading插件的示例demo
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>
总结
以上所述是小编给大家介绍的JQuery+Bootstrap 自定义全屏Loading插件的示例demo,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
- bootstrap可编辑下拉框jquery.editable-select
- bootstrap+jQuery 实现下拉菜单中复选框全选和全不选效果
- Spring shiro + bootstrap + jquery.validate 实现登录、注册功能
- bootstrap+jQuery实现的动态进度条功能示例
- vue中如何引入jQuery和Bootstrap
- Bootstrap jquery.twbsPagination.js动态页码分页实例代码
- jQuery简单实现提交数据出现loading进度条的方法
- jquery显示loading图片直到网页加载完成的方法
- 基于jquery的loading 加载提示效果实现代码
- 基于jquery的loading效果实现代码
相关文章
jQuery实现鼠标滑过商品小图片上显示对应大图片功能【测试可用】
这篇文章主要介绍了jQuery实现鼠标滑过商品小图片上显示对应大图片功能,涉及jQuery事件响应、元素遍历及属性动态操作相关实现技巧,需要的朋友可以参考下2018-04-04
jquery ajax学习笔记2 使用XMLHttpRequest对象的responseXML
使用XMLHttpRequest对象的responseXML的方式来接受XML数据对象的DOM对象2011-10-10
jquery.blockUI.js上传滚动等待效果实现思路及代码
上传滚动等待效果想必大家在很多场合都有见过吧,本文将介绍jquery.blockUI.js实现上传滚动等待效果,感兴趣的你可不要错过了哈,希望可以帮助到你2013-03-03
以jQuery中$.Deferred对象为例讲解promise对象是如何处理异步问题
Promises是一种令代码异步行为更加优雅的抽象,它很有可能是JavaScript的下一个编程范式,一个Promise即表示任务结果,无论该任务是否完成。本文以jQuery中$.Deferred对象为例讲解promise对象是如何处理异步问题,需要的朋友参考下2015-11-11
JQuery 获取多个select标签option的text内容(实例)
下面小编就为大家带来一篇JQuery 获取多个select标签option的text内容(实例)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-09-09


最新评论