Documentation v8.0.38

Preview Downloads Purchase

Overview

BlockUI is an exclusive plugin of Metronic that allows element blocking with overlay and loading indicator.

Usage

BlockUI's global style and scripts bundles and are globally included in all pages.
<link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css"/>
<script src="assets/js/scripts.bundle.js"></script>

Basic Example

Click the below button to block the below content area:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Inceptos imperdiet magna! Sed fusce fames tempus litora venenatis. Ac aliquet leo hendrerit taciti viverra? Nisl suscipit potenti accumsan quis ipsum purus cursus. Suspendisse ultrices morbi in purus lectus dictum porta; Commodo penatibus nec.
var button = document.querySelector("#kt_block_ui_1_button");
var target = document.querySelector("#kt_block_ui_1_target");

var blockUI = new KTBlockUI(target);

button.addEventListener("click", function() {
    if (blockUI.isBlocked()) {
        blockUI.release();
        button.innerText = "Block";
    } else {
        blockUI.block();
        button.innerText = "Release";
    }
});
<div class="rounded border p-10" id="kt_block_ui_1_target">
    Lorem ipsum dolor sit amet....
</div>

Custom Message

Click the below button to block the below content area:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Inceptos imperdiet magna! Sed fusce fames tempus litora venenatis. Ac aliquet leo hendrerit taciti viverra? Nisl suscipit potenti accumsan quis ipsum purus cursus. Suspendisse ultrices morbi in purus lectus dictum porta; Commodo penatibus nec.
var button = document.querySelector("#kt_block_ui_2_button");
var target = document.querySelector("#kt_block_ui_2_target");

var blockUI = new KTBlockUI(target, {
    message: '<div class="blockui-message"><span class="spinner-border text-primary"></span> Loading...</div>',
});

button.addEventListener("click", function() {
    if (blockUI.isBlocked()) {
        blockUI.release();
        button.innerText = "Block";
    } else {
        blockUI.block();
        button.innerText = "Release";
    }
});
<div class="rounded border p-10" id="kt_block_ui_2_target">
    Lorem ipsum dolor sit amet....
</div>

Overlay Class

Use custom class for overlay to change it's background color:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Inceptos imperdiet magna! Sed fusce fames tempus litora venenatis. Ac aliquet leo hendrerit taciti viverra? Nisl suscipit potenti accumsan quis ipsum purus cursus. Suspendisse ultrices morbi in purus lectus dictum porta; Commodo penatibus nec.
var button = document.querySelector("#kt_block_ui_3_button");
var target = document.querySelector("#kt_block_ui_3_target");

var blockUI = new KTBlockUI(target, {
    overlayClass: "bg-danger bg-opacity-25",
});

button.addEventListener("click", function() {
    if (blockUI.isBlocked()) {
        blockUI.release();
        button.innerText = "Block";
    } else {
        blockUI.block();
        button.innerText = "Release";
    }
});
<div class="rounded border p-10" id="kt_block_ui_3_target">
    Lorem ipsum dolor sit amet....
</div>

Modal

Modal content blocking example:
var button = document.querySelector("#kt_block_ui_4_button");
var target = document.querySelector("#kt_block_ui_4_target");

var blockUI = new KTBlockUI(target);

button.addEventListener("click", function(e) {
    e.preventDefault();

    blockUI.block();

    setTimeout(function() {
        blockUI.release();
    }, 3000);
});
<!--begin::Modal-->
<div class="modal fade" tabindex="-1" id="kt_modal_1">
    <div class="modal-dialog modal-dialog-centered mw-650px">
        <div class="modal-content" id="kt_block_ui_4_target">
            ....
        </div>
    </div>
</div>
<!--end::Modal-->

Methods

The following are the BlockUI's functionality methods for more control.
Name Description
Constructor Constructs a new instance of KTBlockUIclass and initializes a Dialer control:
var target = document.querySelector("#kt_blockui_target");
var blockUI = new KTBlockUI(target, options);
For the constructor optionsrefer to the next table.
block() Block target element
blockUI.block();
release Release target element
blockUI.release();
isBlocked() Check if target element is blocked.
if (blockUI.isBlocked() === true) {
    // do something
}
destroy() Removes the component instance from element.
blockUI.destroy();
Static Methods
getInstance(DOMElement element) Get BlockUI instance created and bind to a target element.
var target = document.querySelector("#kt_blockui_target");
var blockUI = KTBlockUI.getInstance(target);

Constructor Options

All options can be passed to the construction during the plugin initialization:
Name Type Default Description
zIndex Object false Custom CSS z-index value of BlockUI's overlay element.
overlayClass String null Custom CSS class for BlockUI overlay element.
overflow String hidden Set's CSS overflow value if BlockUI's target does not have preset overflow value.
message String <span class="spinner-border text-primary"></span> Sets BlockUI's HTML content centered within the target element.

Events

Below are few events for hooking into the Bootstrap BlockUI functionality.
Event Type Description
kt.blockui.block This event is fired before BlockUI is blocked.
var target = document.querySelector("#kt_blockui_target");
var blockUI = new KTBlockUI(target, options);

blockUI.on("kt.blockui.block", function() {
    console.log("before block");
});
kt.blockui.blocked This event is fired after BlockUI is blocked.
var target = document.querySelector("#kt_blockui_target");
var blockUI = new KTBlockUI(target, options);

blockUI.on("kt.blockui.blocked", function() {
    console.log("after blocked");
});
kt.blockui.release This event is fired before BlockUI release.
var target = document.querySelector("#kt_blockui_target");
var blockUI = new KTBlockUI(target, options);

blockUI.on("kt.blockui.release", function() {
    console.log("before release");
});
kt.blockui.released This event is fired after BlockUI is released.
var target = document.querySelector("#kt_blockui_target");
var blockUI = new KTBlockUI(target, options);

blockUI.on("kt.blockui.released", function() {
    console.log("after released");
});

Explore

Metronic Licenses

License FAQs
Regular License
For single end product used by you or one client
$ 39
Extended License
For single SaaS app with paying users
$ 969
Custom License
Reach us for custom license offers.
Buy Now
Learn & Get Inspired

Support at devs.keenthemes.com

Join our developers community to find answer to your question and help others. FAQs
Get Support
Documentation & Videos
From guides and video tutorials, to live demos and code examples to get started.
Plugins & Components
Check out our 300+ in-house components and customized 3rd-party plugins.
Layout Builder
Build your layout, preview it and export the HTML for server side integration.
Metronic Downloads
Download your prefered framework and demo with one click.
What's New
Latest features and improvements added with our users feedback in mind.
Buy now