Introduction

This library allowed you to display loading overlay for your application easily and beautifully.

It contains 52 spinner icons you can choose. JS loading overlay using awesome spinner from Load Awesome. Credit to Load Awesome.

You can use this library to display loading overlay for AJAX request and other things.

This library is very lightweight. The size only 7KB after compressed. No jQuery.

Installation


NPM

						
npm install --save js-loading-overlay
						
					

Yarn

						
yarn add js-loading-overlay
						
					

Without Yarn and NPM

  • Copy the js-loading-overlay.min.js script or js-loading-overlay.js script inside dist folder into your application.
  • You can get the file from here.
  • Or you can use the script directly from CDN here.
  • 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();
						
					

Show Loading Overlay

						
var configs = {
	'overlayBackgroundColor': '#666666',
	'overlayOpacity': 0.6,
	'spinnerIcon': 'ball-circus',
	'spinnerColor': '#000',
	'spinnerSize': '3x',
	'overlayIDName': 'overlay',
	'spinnerIDName': 'spinner',
	'offsetY': 0,
	'offsetX': 0,
	'lockScroll': false,
	'containerID': null,
};

JsLoadingOverlay.show(configs);
						
					

Hide Loading Overlay

						
JsLoadingOverlay.hide();
						
					

Set Options


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();
						
					

List Of Available Spinner

ball-8bits
ball-atom
ball-beat
ball-circus
ball-climbing-dot
ball-clip-rotate
ball-clip-rotate-multiple
ball-clip-rotate-pulse
ball-elastic-dots
ball-fall
ball-fussion
ball-grid-beat
ball-grid-pulse
ball-newton-cradle
ball-pulse
ball-pulse-rise
ball-pulse-sync
ball-rotate
ball-running-dots
ball-scale
ball-scale-multiple
ball-scale-pulse
ball-scale-ripple
ball-scale-ripple-multiple
ball-spin
ball-spin-clockwise
ball-spin-clockwise-fade
ball-spin-clockwise-fade-rotating
ball-spin-fade
ball-spin-fade-rotating
ball-spin-rotate
ball-square-clockwise-spin
ball-square-spin
ball-triangle-path
ball-zig-zag
ball-zig-zag-deflect
cog
cube-transition
fire
line-scale
line-scale-party
line-scale-pulse-out
line-scale-pulse-out-rapid
line-spin-clockwise-fade
line-spin-clockwise-fade-rotating
line-spin-fade
line-spin-fade-rotating
pacman
square-jelly-box
square-loader
square-spin
timer
triangle-skew-spin

Default Options


						
{
	'overlayBackgroundColor': '#666666',
	'overlayOpacity': 0.6,
	'spinnerIcon': 'ball-circus',
	'spinnerColor': '#000',
	'spinnerSize': '3x',
	'overlayIDName': 'overlay',
	'spinnerIDName': 'spinner',
	'offsetY': 0,
	'offsetX': 0,
	'lockScroll': false,
	'containerID': null,
	'spinnerZIndex':99999,
	'overlayZIndex':99998
}
						
					

Custom Options

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. String. Default: overlay. Example: overlay-container
spinnerIDName You can use this to specify the spinner ID name. Useful if the default ID name conflict with your code. String. Default: spinner. Example: spinner-container
offsetX Use this option to adjust the spinner position for X axis. You can specify the value in PX, EM, REM or % String. Default: 0. Example: 15PX, 1REM, 1EM, -10%
offsetY You can use this option to adjust the spinner position for Y axis. You can specify the value in PX, EM, REM or % String. Default: 0. Example: 15PX, 1REM, 1EM, -10%
containerID 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


Overlay Background Color:
Overlay Opacity:
Spinner Icon:
Spinner Color:
Spinner Size:
Overlay ID Name:
Spinner ID Name:
Spinner Icon Offset X:
Spinner Icon Offset Y:
Display Overlay In Container:
Lock Scroll When Loading Overlay Show:
Overlay Z-Index:
Spinner Z-Index:

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.