The script end with min.js is the script after compressed. Recommended to use it in production.
Now you can start using it. Go to Usage section to start using it.
Changelog
All the change are documented in Github. You can view Github
Usage
Import using ES6 module
If you import using ES6 module you can use this library in framework like Vue.js, ReactJS, Angular and other framework.
Note
Only available for user installed through NPM or Yarn
// Import the script.
import 'js-loading-overlay'
// Show the loading overlay with default config.
JsLoadingOverlay.show();
// Hide the loading overlay.
JsLoadingOverlay.hide();
Load using script tag
Note
Please make sure you specify the valid path to the script.
// Import the script from your local.
<script src="js-loading-overlay.min.js"></script>
// OR
// Import the script from the CDN.
<script src="https://cdn.jsdelivr.net/npm/js-loading-overlay@1.1.0/dist/js-loading-overlay.min.js"></script>
// Show the loading overlay with default config.
JsLoadingOverlay.show();
// Hide the loading overlay.
JsLoadingOverlay.hide();
You can use the setOptions method to override the default options.
Useful if you want to display the loading overlay in multiple page and you want to set the options one time only
// Override the default options.
// Imagine you have multiple page need to show the loading overlay.
// App.js file. The main js file for you application.
// You set the options one time only.
JsLoadingOverlay.setOptions({
'overlayBackgroundColor': '#666666',
'overlayOpacity': 0.6,
'spinnerIcon': 'cog',
'spinnerColor': '#000',
'spinnerSize': '2x',
'overlayIDName': 'overlay',
'spinnerIDName': 'spinner',
'offsetY': 0,
'offsetX': 0,
'lockScroll': false,
'containerID': null,
});
// Other place you want to display the loading overlay.
// Only need to call JsLoadingOverlay.show(). No need to call JsLoadingOverlay.show() with the options again.
// It will display the loading overlay based on the config above.
// Product.js file.
JsLoadingOverlay.show();
// Checkout.js file.
JsLoadingOverlay.show();
You can use any of the options below to customize the loading overlay according ti your need.
Option
Description
Value
overlayBackgroundColor
You can use this option to specify the background color of the loading overlay.
HTML color code. Default: #666666. Example: #ECECEC, grey
overlayOpacity
You can use this option to specify the opacity of the loading overlay.
Available value from 0 to 1. Default: 0.6. Example: 0.5, 0.7
spinnerIcon
You can use this option if you want to choose different icon for the spinner. Got 52 spinners you can choose. Go to playground to see available spinner.
Default: ball-circus
spinnerColor
You can use this specify the color of the loading overlay spinner.
HTML color code. Default: #000. Example: #ECECEC, grey
spinnerSize
You can use this tp specify the size of the loading overlay spinner.
String. Default: 1x. Available values: 1x, 2x, 3x
overlayIDName
You can use this to specify the overlay ID name. Useful if the default ID name conflict with your code.
You can use this option to display the loading overlay inside the container.
For example you have a table and when user click next page button, you want to show the loading overlay while waiting for the data.
Just specify the ID name without #.
String. Default: null. Example: users-table
lockScroll
You can use this option if you want to lock the scroll when loading overlay has been shown.
For example, if your page has form and when user submit the form, you want to display the loading overlay and prevent user from scroll to other section.
Boolean. Default: false. Example: true
overlayZIndex
You can use this option if you want to specify custom z-index.
Maybe the default z-index value not suitable with you existing code.
Numeric. Default: 9998. Example: 999
spinnerZIndex
You can use this option if you want to specify custom z-index.
Maybe the default z-index value not suitable with you existing code.
Numeric. Default: 9999. Example: 1000
Playground
Show Loading Overlay
Reset Options
Code Output
JSLoadingOverlay.show();
Roadmap
Timer feature. Able to hide automatically after certain period.
Able to display loading text with the spinner
Able to display loading overlay around the container. For example want to display loading overlay next to the button.