| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /**
- * Created by chen on 2017/10/31.
- */
- jQuery.bootstrapLoading = {
- isLoading: function () {
- return $('#loadingPage').is(':visible');
- },
- start: function (options) {
- if(this.isLoading()){
- return;
- }
- var defaults = {
- opacity: 0.5,
- //loading页面透明度
- // backgroundColor: "#FFFFFF",
- //loading页面背景色
- borderColor: "#bbb",
- //提示边框颜色
- borderWidth: 1,
- //提示边框宽度
- borderStyle: "solid",
- //提示边框样式
- loadingTips: "Loading, please wait...",
- //提示文本
- TipsColor: "#fff",
- //提示颜色
- delayTime: 500,
- //页面加载完成后,加载页面渐出速度
- zindex: 999,
- //loading页面层次
- sleep: 0
- //设置挂起,等于0时则无需挂起
- }
- var options = $.extend(defaults, options);
- //获取页面宽高
- var _PageHeight = document.documentElement.clientHeight,
- _PageWidth = document.documentElement.clientWidth;
- //在页面未加载完毕之前显示的loading Html自定义内容
- //var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;border-color:' + options.borderColor + ';border-style:' + options.borderStyle + ';border-width:' + options.borderWidth + 'px; height:80px; line-height:80px; padding-left:80px; padding-right: 5px;border-radius:10px; background: ' + options.backgroundColor + ' url(/Content/bootstrap-loading/images/loading.gif) no-repeat 5px center; color:' + options.TipsColor + ';font-size:20px;">' + options.loadingTips + '</div></div>';
- var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;">' +'<div class="text-green"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i> <span class="sr-only">Loading...</span> </div> </div></div>';
- //呈现loading效果
- $("body").append(_LoadingHtml);
- //获取loading提示框宽高
- var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
- _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
- //计算距离,让loading提示框保持在屏幕上下左右居中
- var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
- _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
- $("#loadingTips").css({
- "left": _LoadingLeft + "px",
- "top": _LoadingTop + "px"
- });
- //监听页面加载状态
- document.onreadystatechange = PageLoaded;
- //当页面加载完成后执行
- function PageLoaded() {
- if (document.readyState == "complete") {
- var loadingMask = $('#loadingPage');
- setTimeout(function () {
- loadingMask.animate({
- "opacity": 0
- },
- options.delayTime,
- function () {
- $(this).hide();
- });
- },
- options.sleep);
- }
- }
- },
- end: function () {
- $("#loadingPage").remove();
- }
- }
- const SCComponent = (() => {
- /*
- * 假滚动条,0 - 80% 快, 80% - 95%很慢,95%开始停住,直到调用end方法
- * */
- const InitProgressBar = (() => {
- function ProgressBar($modal = $('#progress'), $title = $('#progress-title'),
- $content = $('#progress-content'), $bar = $('#progressBar')) {
- this.$modal = $modal;
- this.$title = $title;
- this.$content = $content;
- this.$bar = $bar;
- }
- //显示滚动条,自动处理滚动条速度
- ProgressBar.prototype.start = function (title, content) {
- this.$title.text(title);
- this.$content.text(content);
- this.$bar.css('width', `0%`);
- this.$modal.modal('show');
- this.outer = setInterval(() => {
- let curWidth = parseInt(this.$bar[0].style.width.replace('%', ''));
- curWidth = parseInt(curWidth + 2);
- this.$bar.css('width', `${curWidth}%`);
- if (curWidth >= 80) {
- clearInterval(this.outer);
- }
- }, 100);
- this.inner = setInterval(() => {
- let curWidth = parseFloat(this.$bar[0].style.width.replace('%', ''));
- if (curWidth >= 80) {
- curWidth = parseFloat(curWidth + 0.1);
- this.$bar.css('width', `${curWidth}%`);
- if (curWidth >= 95) {
- clearInterval(this.inner);
- }
- }
- }, 500);
- };
- //结束显示滚动条,滚动条从当前位置滚到100% 消失
- ProgressBar.prototype.end = function () {
- if (this.outer) {
- clearInterval(this.outer);
- }
- if (this.inner) {
- clearInterval(this.inner);
- }
- $('#progressBar').css('width', '100%');
- setTimeout(() => {
- this.$modal.modal('hide');
- }, 500);
- };
- return ProgressBar;
- })();
- return {InitProgressBar}
- })();
|