当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery NProgress.js加载进度插件的简单使用方法

jQuery NProgress.js加载进度插件的简单使用方法

2018年02月08日  | 移动技术网IT编程  | 我要评论

nprogress.js

  说明:

    nprogress是基于jquery的,且版本要 >1.8

  下载地址:

    

  api:   

nprogress.start() — 启动进度条
    nprogress.set(0.4) — 将进度设置到具体的百分比位置
    nprogress.inc() — 少量增加进度
    nprogress.done() — 将进度条标为完成状态

  使用步骤:

    1. 引入

<link rel="stylesheet" type="text/css" href="css/nprogress.css" rel="external nofollow" >
 <script src="js/nprogress.js" type="text/javascript"></script><br>//还有jquery要之前引入进来 

    2. 使用场景一:页面加载的效果  开始页面加载开始进度条  页面加载好  结束进度条:

<em id="__mcedel"><script>
$(function() {
   nprogress.start();
   $(window).load(function() {
     nprogress.done();
 });
</script>
</em>

    3.使用场景二:ajax发送的效果  开始发送开始进度条  成功后  结束进度条:

<script>
$(window).ajaxstart(function () {
  nprogress.start();
});
$(window).ajaxstop(function () {
  nprogress.done();
});
</script>
//技巧总结  此方法挂在window上 是为了监听项目中所有的ajax请求
//ajax事件 可参考 jquery 文档 http://jquery.cuishifeng.cn/

总结

以上所述是小编给大家介绍的jquery nprogress.js加载进度插件的简单使用方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网