Home  >  Article  >  Web Front-end  >  pace.js – Web page automatic loading progress bar plug-in

pace.js – Web page automatic loading progress bar plug-in

高洛峰
高洛峰Original
2016-12-16 16:45:151324browse

Introduce Pace.js into the page, and the page will automatically monitor your requests (including Ajax requests). When the event loop lags, the loading status and progress will be recorded on the page. This plug-in has good compatibility and is compatible with all mainstream plug-ins above IE8. What’s more, its power is that you can also introduce the theme style of the loading progress bar. You can choose any color and multiple animation effects (such as simplicity, flash , MAC OSX, left padding, top padding, counter and bounce, etc. animation effects), if you are good at modifying CSS animations, then you can make unlimited possibilities of animations to add personalized features to your website!

How to use

Introduce Pace.js and theme files:

<head>
  <script src="/pace/pace.js"></script>
  <link href="/pace/themes/pace-theme-barber-shop.css" rel="external nofollow"  rel="stylesheet" />
</head>

Custom configuration

Pace.js will be automatically loaded into the page without being hooked to any code, and the progress will be automatically detected. If you want to make some adjustments, you can set window.paceOptions to customize the configuration:

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

You can also put the custom settings in the script tag, for example:

<script data-pace-options=&#39;{ "ajax": false }&#39; src=&#39;pace.js&#39;></script>

If you use AMD or Browserify to load the module, you It can be set like this (for example: start):

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

Use API

Pace.js public API list:

Pace.start: Start displaying the progress bar, if you are not using AMD or Browserify to load the module, This will be executed by default.

Pace.restart: The progress bar is reloaded and displayed.

Pace.stop: Hide the progress bar and stop loading.

Pace.track: Monitor one or more request tasks.

Pace.ignore: Ignore one or more request tasks.



For more articles on pace.js – Web page automatic loading progress bar plug-in, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn