官网下载地址:http://ricostacruz.com/nprogress/

npropress.css

/* Make clicks pass-through */
#nprogress {
pointer-events: none;
} #nprogress .bar {
background: #29d; position: fixed;
z-index:;
top:;
left:;
width: 100%;
height:5px;
} /* Fancy blur effect */
#nprogress .peg {
display: block;
position: absolute;
right: 0px;
width: 100px;
height: 100%;
box-shadow: 0 0 10px #29d, 0 0 5px #29d;
opacity: 1.0; -webkit-transform: rotate(3deg) translate(0px, -4px);
-ms-transform: rotate(3deg) translate(0px, -4px);
transform: rotate(3deg) translate(0px, -4px);
} /* Remove these to get rid of the spinner */
#nprogress .spinner {
display: block;
position: fixed;
z-index:;
top: 15px;
right: 15px;
} #nprogress .spinner-icon {
width: 18px;
height: 18px;
box-sizing: border-box; border: solid 2px transparent;
border-top-color: #29d;
border-left-color: #29d;
border-radius: 50%; -webkit-animation: nprogress-spinner 400ms linear infinite;
animation: nprogress-spinner 400ms linear infinite;
} .nprogress-custom-parent {
overflow: hidden;
position: relative;
} .nprogress-custom-parent #nprogress .spinner,
.nprogress-custom-parent #nprogress .bar {
position: absolute;
} @-webkit-keyframes nprogress-spinner {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes nprogress-spinner {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

npropress.js

/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
* @license MIT */ ;(function(root, factory) { if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.NProgress = factory();
} })(this, function() {
var NProgress = {}; NProgress.version = '0.2.0'; var Settings = NProgress.settings = {
minimum: 0.08,
easing: 'linear',
positionUsing: '',
speed: 200,
trickle: true,
trickleSpeed: 200,
showSpinner: true,
barSelector: '[role="bar"]',
spinnerSelector: '[role="spinner"]',
parent: 'body',
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
}; /**
* Updates configuration.
*
* NProgress.configure({
* minimum: 0.1
* });
*/
NProgress.configure = function(options) {
var key, value;
for (key in options) {
value = options[key];
if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value;
} return this;
}; /**
* Last number.
*/ NProgress.status = null; /**
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
*
* NProgress.set(0.4);
* NProgress.set(1.0);
*/ NProgress.set = function(n) {
var started = NProgress.isStarted(); n = clamp(n, Settings.minimum, 1);
NProgress.status = (n === 1 ? null : n); var progress = NProgress.render(!started),
bar = progress.querySelector(Settings.barSelector),
speed = Settings.speed,
ease = Settings.easing; progress.offsetWidth; /* Repaint */ queue(function(next) {
// Set positionUsing if it hasn't already been set
if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS(); // Add transition
css(bar, barPositionCSS(n, speed, ease)); if (n === 1) {
// Fade out
css(progress, {
transition: 'none',
opacity: 1
});
progress.offsetWidth; /* Repaint */ setTimeout(function() {
css(progress, {
transition: 'all ' + speed + 'ms linear',
opacity: 0
});
setTimeout(function() {
NProgress.remove();
next();
}, speed);
}, speed);
} else {
setTimeout(next, speed);
}
}); return this;
}; NProgress.isStarted = function() {
return typeof NProgress.status === 'number';
}; /**
* Shows the progress bar.
* This is the same as setting the status to 0%, except that it doesn't go backwards.
*
* NProgress.start();
*
*/
NProgress.start = function() {
if (!NProgress.status) NProgress.set(0); var work = function() {
setTimeout(function() {
if (!NProgress.status) return;
NProgress.trickle();
work();
}, Settings.trickleSpeed);
}; if (Settings.trickle) work(); return this;
}; /**
* Hides the progress bar.
* This is the *sort of* the same as setting the status to 100%, with the
* difference being `done()` makes some placebo effect of some realistic motion.
*
* NProgress.done();
*
* If `true` is passed, it will show the progress bar even if its hidden.
*
* NProgress.done(true);
*/ NProgress.done = function(force) {
if (!force && !NProgress.status) return this; return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
}; /**
* Increments by a random amount.
*/ NProgress.inc = function(amount) {
var n = NProgress.status; if (!n) {
return NProgress.start();
} else if(n > 1) {
return;
} else {
if (typeof amount !== 'number') {
if (n >= 0 && n < 0.2) { amount = 0.1; }
else if (n >= 0.2 && n < 0.5) { amount = 0.04; }
else if (n >= 0.5 && n < 0.8) { amount = 0.02; }
else if (n >= 0.8 && n < 0.99) { amount = 0.005; }
else { amount = 0; }
} n = clamp(n + amount, 0, 0.994);
return NProgress.set(n);
}
}; NProgress.trickle = function() {
return NProgress.inc();
}; /**
* Waits for all supplied jQuery promises and
* increases the progress as the promises resolve.
*
* @param $promise jQUery Promise
*/
(function() {
var initial = 0, current = 0; NProgress.promise = function($promise) {
if (!$promise || $promise.state() === "resolved") {
return this;
} if (current === 0) {
NProgress.start();
} initial++;
current++; $promise.always(function() {
current--;
if (current === 0) {
initial = 0;
NProgress.done();
} else {
NProgress.set((initial - current) / initial);
}
}); return this;
}; })(); /**
* (Internal) renders the progress bar markup based on the `template`
* setting.
*/ NProgress.render = function(fromStart) {
if (NProgress.isRendered()) return document.getElementById('nprogress'); addClass(document.documentElement, 'nprogress-busy'); var progress = document.createElement('div');
progress.id = 'nprogress';
progress.innerHTML = Settings.template; var bar = progress.querySelector(Settings.barSelector),
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
parent = document.querySelector(Settings.parent),
spinner; css(bar, {
transition: 'all 0 linear',
transform: 'translate3d(' + perc + '%,0,0)'
}); if (!Settings.showSpinner) {
spinner = progress.querySelector(Settings.spinnerSelector);
spinner && removeElement(spinner);
} if (parent != document.body) {
addClass(parent, 'nprogress-custom-parent');
} parent.appendChild(progress);
return progress;
}; /**
* Removes the element. Opposite of render().
*/ NProgress.remove = function() {
removeClass(document.documentElement, 'nprogress-busy');
removeClass(document.querySelector(Settings.parent), 'nprogress-custom-parent');
var progress = document.getElementById('nprogress');
progress && removeElement(progress);
}; /**
* Checks if the progress bar is rendered.
*/ NProgress.isRendered = function() {
return !!document.getElementById('nprogress');
}; /**
* Determine which positioning CSS rule to use.
*/ NProgress.getPositioningCSS = function() {
// Sniff on document.body.style
var bodyStyle = document.body.style; // Sniff prefixes
var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
('MozTransform' in bodyStyle) ? 'Moz' :
('msTransform' in bodyStyle) ? 'ms' :
('OTransform' in bodyStyle) ? 'O' : ''; if (vendorPrefix + 'Perspective' in bodyStyle) {
// Modern browsers with 3D support, e.g. Webkit, IE10
return 'translate3d';
} else if (vendorPrefix + 'Transform' in bodyStyle) {
// Browsers without 3D support, e.g. IE9
return 'translate';
} else {
// Browsers without translate() support, e.g. IE7-8
return 'margin';
}
}; /**
* Helpers
*/ function clamp(n, min, max) {
if (n < min) return min;
if (n > max) return max;
return n;
} /**
* (Internal) converts a percentage (`0..1`) to a bar translateX
* percentage (`-100%..0%`).
*/ function toBarPerc(n) {
return (-1 + n) * 100;
} /**
* (Internal) returns the correct CSS for changing the bar's
* position given an n percentage, and speed and ease from Settings
*/ function barPositionCSS(n, speed, ease) {
var barCSS; if (Settings.positionUsing === 'translate3d') {
barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' };
} else if (Settings.positionUsing === 'translate') {
barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' };
} else {
barCSS = { 'margin-left': toBarPerc(n)+'%' };
} barCSS.transition = 'all '+speed+'ms '+ease; return barCSS;
} /**
* (Internal) Queues a function to be executed.
*/ var queue = (function() {
var pending = []; function next() {
var fn = pending.shift();
if (fn) {
fn(next);
}
} return function(fn) {
pending.push(fn);
if (pending.length == 1) next();
};
})(); /**
* (Internal) Applies css properties to an element, similar to the jQuery
* css method.
*
* While this helper does assist with vendor prefixed property names, it
* does not perform any manipulation of values prior to setting styles.
*/ var css = (function() {
var cssPrefixes = [ 'Webkit', 'O', 'Moz', 'ms' ],
cssProps = {}; function camelCase(string) {
return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) {
return letter.toUpperCase();
});
} function getVendorProp(name) {
var style = document.body.style;
if (name in style) return name; var i = cssPrefixes.length,
capName = name.charAt(0).toUpperCase() + name.slice(1),
vendorName;
while (i--) {
vendorName = cssPrefixes[i] + capName;
if (vendorName in style) return vendorName;
} return name;
} function getStyleProp(name) {
name = camelCase(name);
return cssProps[name] || (cssProps[name] = getVendorProp(name));
} function applyCss(element, prop, value) {
prop = getStyleProp(prop);
element.style[prop] = value;
} return function(element, properties) {
var args = arguments,
prop,
value; if (args.length == 2) {
for (prop in properties) {
value = properties[prop];
if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value);
}
} else {
applyCss(element, args[1], args[2]);
}
}
})(); /**
* (Internal) Determines if an element or space separated list of class names contains a class name.
*/ function hasClass(element, name) {
var list = typeof element == 'string' ? element : classList(element);
return list.indexOf(' ' + name + ' ') >= 0;
} /**
* (Internal) Adds a class to an element.
*/ function addClass(element, name) {
var oldList = classList(element),
newList = oldList + name; if (hasClass(oldList, name)) return; // Trim the opening space.
element.className = newList.substring(1);
} /**
* (Internal) Removes a class from an element.
*/ function removeClass(element, name) {
var oldList = classList(element),
newList; if (!hasClass(element, name)) return; // Replace the class name.
newList = oldList.replace(' ' + name + ' ', ' '); // Trim the opening and closing spaces.
element.className = newList.substring(1, newList.length - 1);
} /**
* (Internal) Gets a space separated list of the class names on the element.
* The list is wrapped with a single space on each end to facilitate finding
* matches within the list.
*/ function classList(element) {
return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' ');
} /**
* (Internal) Removes an element from the DOM.
*/ function removeElement(element) {
element && element.parentNode && element.parentNode.removeChild(element);
} return NProgress;
});

引入这俩文件

<link rel="stylesheet" type="text/css" href="nprogress.css"/>
<script src="nprogress.js"></script>

基本用法:

NProgress.start(); //显示进度条
NProgress.done(); //完成进度条
NProgress.set(0.4); //设置百分比
NProgress.inc(); //增加一点点

配置:

minimum:设置最低百分比

NProgress.configure({minimum:0.3});

ease:调整动画设置,ease可传递CSS3缓冲动画字符串(如ease、linear、ease-in、ease-out、ease-in-out、cubic-bezier)。speed为动画速度(单位ms)。

NProgress.configure({ease:'ease',speed:500});

showSpinner:进度环显示隐藏

NProgress.configure({showSpinner: false});

npropress进度条插件的使用的更多相关文章

  1. YprogressBar,html5进度条样式,js进度条插件

    简介 YprogressBar是一款基于HTML5的进度条插件. YprogressBar是一款轻量级进度条插件,使用方便,资源占用少,模仿好压的解压界面,带有数字显示,同时支持在描述中增加参数,以动 ...

  2. 简单实用的纯CSS百分比圆形进度条插件

    percircle是一款简单实用的纯CSS百分比圆形进度条插件.你不需要做任何设置,只需要按该圆形进度条插件提供的标准HTML结构来编写代码,就可以生成一个漂亮的百分比圆形进度条. 首先要做的就是引入 ...

  3. 一个Notification 进度条插件(android,NJS实现,直接就可使用)

    参考文章:http://ask.dcloud.net.cn/article/503 源码地址下载 如题,分享一个Notification 进度条插件(android,用js调用原生api实现,直接就可 ...

  4. 30款基于 jQuery & CSS3 的加载动画和进度条插件

    我们所生活每一天看到的新技术或新设计潮流的兴起,Web 开发正处在上升的时代.HTML5 & CSS3 技术的发展让 Web 端可以实现的功能越来越强大. 加载动画和进度条使网站更具吸引力.该 ...

  5. JQuery中简约的进度条插件推荐

    JQuery Progress Bar是基于JQuery开发的进度条插件,秉承了JQuery的简约哲学.不仅容易使用,而且可以轻松定制外观.对于使用了JQuery框架的项目来说,需要使用进度条控件时这 ...

  6. 基于Jquery的进度条插件(实用)

    Spin.js 最喜欢这款插件了,动画图片的长度.粗细.速度和角度都可以灵活控制,想要做成什么样都可以. 源码下载    在线演示   Percentage Loader 一款轻量的 jQuery 进 ...

  7. 简单的jquery进度条插件LineProgressbar.js,myProgress.js

    参考   http://www.lanrenzhijia.com/jquery/4121.html demo下载 <script src="js/jquery.lineProgress ...

  8. HTML5圆形百分比进度条插件circleChart

    在页面中引入jquery和circleChart.min.js文件. <script src="path/to/jquery.min.js"></script&g ...

  9. ajax页面加载进度条插件

    下面两个都是youtube视频的加载进度条效果的ajax插件 一.官网:http://ricostacruz.com/nprogress/官网 github:https://github.com/rs ...

随机推荐

  1. 使用sequelize对数据库进行增删改查

    由于本人对于命令比较执着,所以基本都是在命令下操作的,喜欢使用命令的可以使用Cmder,需要安装.配置的可以参考这篇文章: https://www.cnblogs.com/ziyoublog/p/10 ...

  2. javascript原型链[图]

  3. iOS 作为蓝牙外设广播信息

    苹果蓝牙后台的限制,原本广播会有两个段分别是localName和serviceUUID这两块,但现在后台广播时,是不发送在这两段的 手机app可以作为一个蓝牙外设端来模拟外设硬件,但广播包里的数据只能 ...

  4. 关于Tomcat服务器中的协议及请求过程

    关于Tomcat服务器中采用的协议:在Tomcat的server.xml文件中可以找到如下几个Connector <!-- 1. HTTP --> <Connector port=& ...

  5. 空指针异常:解决 RequestContextHolder.getRequestAttributes()为空的问题

    现象:实现Feign请求拦截器时,执行如下代码,报空指针异常 ServletRequestAttributes attributes = (ServletRequestAttributes) Requ ...

  6. 克隆Linux系统的网卡设置

    虚拟机里创建新主机使用克隆的办法,可以大大节省主机反复安装消耗的时间精力.但克隆出来的主机网卡及配置文件会发生改变,给我们在进行网卡设置时的很多麻烦.题主本文将从Linux里CentOS6发行版克隆的 ...

  7. Docker——概念学习

    百度百科概念: Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化.容器是完全 ...

  8. java加密算法-SHA1

    public class SHAUtil { /*** * SHA加密 生成40位SHA码 * @param 待加密字符串 * @return 返回40位SHA码 */ public static S ...

  9. 基于Java+Selenium的WebUI自动化测试框架(十四)-----使用TestNG的Sample

    到目前为止,我们所写的东西,都是集中在如何使用Selenium和Java来定位和读取元素.那么,到底如何具体开展测试,如何实现参数化,如何实现判定呢?下面,我们来看看Java应用程序的测试框架吧. 当 ...

  10. 51nod 2485 小b重排字符串

    小b有一个字符串S,现在她希望重排列S,使得S中相邻字符不同. 请你判断小b是否可能成功. 样例解释:将"aab"重排为"aba"即可. 收起   输入 输入一 ...