页面进度条插件pace.js

Pace.js会自动加载到页面中,不须要挂接到任何代码,会自动检测进度。若是你想作一些调整,你能够设置window.paceOptions来自定义配置:ajax

paceOptions = {
  // Disable the 'elements' source
  elements: false,
  
  // Only show the progress on regular and ajax-y page navigation,
  // not every request
  restartOnRequestAfter: false
  }

你也能够将自定义设置放到script标签内,例如:spa

 <script data-pace-options='{ "ajax": true, "eventLag": true , "document": true}' src='./js/pace.min.js'></script>

若是你使用AMD或者Browserify来加载模块的话,你能够经过这样子来设置(例如:start):rest

define(['pace'], function(pace){
  pace.start({
    document: false
  });
});

Pace.js公开的API列表:code

  • Pace.start:开始显示进度条,若是你不是使用AMD或者Browserify来加载模块的话,这个会默认执行。
  • Pace.restart:进度条从新加载以及显示。
  • Pace.stop:隐藏进度条以及中止加载。
  • Pace.track:监测一个或者多个请求任务。
  • Pace.ignore:忽略一个或者多个请求任务。
相关文章
相关标签/搜索