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 'elements' 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='{ "ajax": false }' src='pace.js'></script>
If you use AMD or Browserify to load the module, you It can be set like this (for example: start):
define(['pace'], 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!