jquery模拟进度条实现方法


Posted in Javascript onAugust 03, 2015

本文实例讲述了jquery模拟进度条实现方法。分享给大家供大家参考。具体如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>js模拟进度条练习</title>
<script type='text/javascript' src="http://xiazai.3water.com/201508/yuanma/jquery-1.8.0.min.js"></script>
<script type='text/javascript' src='http://xiazai.3water.com/201508/yuanma/jquery.artDialog.js?skin=default'></script>
<style>
body{ font-size:12px}
.aui_nw, .aui_ne, .aui_sw, .aui_se { height: 1px; width: 1px; }
.aui_outer, .aui_inner { border: 0; }
.aui_state_lock .aui_border { box-shadow: 0 0 10px rgba(0, 0, 0, .8); }
</style>
</head>
<body>
<button id="starLoading">显示进度条</button>
<div id="msgHtml">https://3water.com</div>
</body>
</html>
<script>
  (function(w){
    var _html='<div style="line-height: 30px;text-align: center;">正在为您载入数据,请稍后……</div><div id="jsLoadOuter" style="width:250px;height:8px;border:#6BAAC9 solid 1px; background:#C0EBFF; margin:0 auto;box-shadow: 0 0 3px #2E94BB;padding:1px"><div id="jsLoadInner" style="background:#54AEE0;height:100%;width:0"></div></div>';
    var __g;
    var _maxWidth=100;
    var _nowWidth=0;
    var _speed=30;
    var _step=2;
    var __time;
    progress={
      render:function(fn){
        fn&&fn(_html);
        _nowWidth=0;
        __g=document.getElementById('jsLoadInner');
        this.fx();
      },
      complete:function(fn){
        clearTimeout(__time);
        progress.completeFn=fn;
        this.setOver();
      },     
      setOver:function(){
        var _stepa=_step*1.5;
        if(_nowWidth<_maxWidth){
          _nowWidth=_nowWidth-0+_stepa;
          parseInt(_nowWidth)>parseInt(_maxWidth)?_nowWidth=_maxWidth:'';
          __g.style.width=''+_nowWidth+'%';
          _speed=(_maxWidth-_nowWidth)/1000;
          __time=setTimeout('progress.setOver()',_speed) ;
        }else{
          clearTimeout(__time);
          progress.completeFn&&progress.completeFn();
        };
      },
      fx:function(){
        var _stepa=_step;
        if(_nowWidth<_maxWidth-5){
          _stepa=_nowWidth>_maxWidth*0.6?(_stepa*0.02):_stepa;
          _nowWidth=_nowWidth-0+_stepa;
          parseInt(_nowWidth)>parseInt(_maxWidth)?_nowWidth=_maxWidth:'';
          __g.style.width=''+_nowWidth+'%';
          __time=setTimeout('progress.fx()',_speed);
        }else{
          clearTimeout(__time);
        };
      }
    }
    w.progress=progress;
  })(window)
  //
  $(function(){
    showLoading();
    $('body')
    .on('click','#starLoading',function(){
      showLoading();         
    })       
  })
  function showLoading(){
    //开始显示进度条
    progress.render(function(html){
        art.dialog({id:"jsLoadingDialog",title:"\u6b63\u5728\u52a0\u8f7d\u4e2d\u2026\u2026",cancel:!1,lock:!0,background:"#fff",fixed:!0,content:html});
    }); 
    //请求完成后完成进度条,,,模拟10秒后请求完成
    setTimeout(function(){
      progress.complete(function(html){
        art.dialog.list['jsLoadingDialog']&&art.dialog.list['jsLoadingDialog'].close();
        $('#msgHtml').html('进度条已走完');
      });
    },10000);    
  };
</script>

运行效果如下图所示:

jquery模拟进度条实现方法

希望本文所述对大家的jquery程序设计有所帮助。

Javascript 相关文章推荐
Javascript实现的分页函数
Feb 07 Javascript
初识javascript 文档碎片
Jul 13 Javascript
js监听键盘事件示例代码
Jul 26 Javascript
jquery自动填充勾选框即把勾选框打上true
Mar 24 Javascript
js 求时间差的实现代码
Apr 26 Javascript
JavaScript字符串对象(string)基本用法示例
Jan 18 Javascript
Bootstrap modal 多弹窗之叠加关闭阴影遮罩问题的解决方法
Feb 27 Javascript
Node.js连接mongodb实例代码
Jun 06 Javascript
详解用函数式编程对JavaScript进行断舍离
Sep 18 Javascript
JavaScript面试出现频繁的一些易错点整理
Mar 29 Javascript
Vue如何实现监听组件原生事件
Jul 03 Javascript
微信小程序实现自定义底部导航
Nov 18 Javascript
js实现圆盘记速表
Aug 03 #Javascript
包含中国城市的javascript对象实例
Aug 03 #Javascript
jQuery跨域问题解决方案
Aug 03 #Javascript
javascript实现超炫的向上滑行菜单实例
Aug 03 #Javascript
提高jQuery性能优化的技巧
Aug 03 #Javascript
jquery简单实现幻灯片的方法
Aug 03 #Javascript
JS拖拽插件实现步骤
Aug 03 #Javascript
You might like
php的header和asp中的redirect比较
2006/10/09 PHP
精通php的十大要点(上)
2009/02/04 PHP
php标签云的实现代码
2012/10/10 PHP
php简单smarty入门程序实例
2015/06/11 PHP
Yii实现复选框批量操作实例代码
2017/03/15 PHP
表单元素的submit()方法和onsubmit事件应用概述
2013/02/01 Javascript
javascript中Math.random()使用详解
2015/04/15 Javascript
jQuery实现智能判断固定导航条或侧边栏的方法
2016/09/04 Javascript
NodeJS 实现手机短信验证模块阿里大于功能
2017/06/19 NodeJs
js前端导出Excel的方法
2017/11/01 Javascript
详解 javascript对象创建模式
2020/10/30 Javascript
vue 导航守卫和axios拦截器有哪些区别
2020/12/19 Vue.js
[02:04]2014DOTA2国际邀请赛 BBC小组赛第三天总结
2014/07/12 DOTA
[50:15]VP vs Mineski 2018国际邀请赛淘汰赛BO3 第二场 8.22
2018/08/23 DOTA
python调用java的Webservice示例
2014/03/10 Python
python itchat实现微信自动回复的示例代码
2017/08/14 Python
Python PyQt5标准对话框用法示例
2017/08/23 Python
Django ORM框架的定时任务如何使用详解
2017/10/19 Python
Python简单计算数组元素平均值的方法示例
2017/12/26 Python
python实现简单飞行棋
2020/02/06 Python
python递归调用中的坑:打印有值, 返回却None
2020/03/16 Python
python和php学习哪个更有发展
2020/06/17 Python
PyTorch之nn.ReLU与F.ReLU的区别介绍
2020/06/27 Python
golang/python实现归并排序实例代码
2020/08/30 Python
详解HTML5中rel属性的prefetch预加载功能使用
2016/05/06 HTML / CSS
美国校服网上商店:French Toast
2019/10/08 全球购物
文员自我评价怎么写
2013/09/19 职场文书
面试求职的个人自我评价
2013/11/16 职场文书
业务代表的岗位职责
2013/11/16 职场文书
应届毕业生个人自荐信范文
2013/11/30 职场文书
无偿献血倡议书
2014/04/14 职场文书
四风批评与自我批评范文
2014/10/14 职场文书
贷款工资证明范本
2015/06/12 职场文书
在校学生证明格式
2015/06/24 职场文书
java调用Restful接口的三种方法
2021/08/23 Java/Android
Redis基本数据类型哈希Hash常用操作命令
2022/06/01 Redis