Quick Overview
The blockui
library is a jQuery plugin that provides a simple and customizable way to block the user interface (UI) of a web application. It allows developers to display a blocking overlay with a custom message or spinner, preventing user interaction with the underlying content.
Pros
- Ease of Use: The library provides a straightforward API for quickly adding and removing blocking overlays, making it easy to integrate into existing projects.
- Customization: Users can customize the appearance of the blocking overlay, including the message, spinner, and background color, to match the branding and design of their application.
- Cross-browser Compatibility: The library is designed to work across a wide range of modern web browsers, ensuring consistent behavior and appearance.
- Active Development: The project is actively maintained, with regular updates and bug fixes, ensuring its continued relevance and reliability.
Cons
- Dependency on jQuery: The
blockui
library is built on top of the jQuery library, which may be a concern for developers who prefer to use a more lightweight or modern JavaScript framework. - Limited Functionality: While the library provides a basic blocking functionality, it may lack advanced features or integration with other UI components that some developers might require.
- Potential Performance Impact: Depending on the size and complexity of the blocking overlay, the library may have a slight performance impact on the overall user experience, especially on slower devices or networks.
- Lack of Native Support: The library is not a native JavaScript implementation, which means it may not integrate as seamlessly with some modern JavaScript frameworks and libraries.
Code Examples
Here are a few examples of how to use the blockui
library:
- Blocking the Entire Page:
$.blockUI({
message: '<h1>Please wait...</h1>',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: 0.5,
color: '#fff'
}
});
This code will display a blocking overlay with a custom message and styling across the entire page.
- Blocking a Specific Element:
$('#myElement').block({
message: '<h1>Loading...</h1>',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: 0.5,
color: '#fff'
}
});
This code will display a blocking overlay on the #myElement
element, preventing user interaction with that specific part of the page.
- Unblocking the UI:
$.unblockUI();
This code will remove the blocking overlay and restore the user's ability to interact with the page.
Getting Started
To use the blockui
library, follow these steps:
- Include the jQuery library in your HTML file:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
- Include the
blockui
library in your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70.0-2018.05.02/jquery.blockUI.min.js"></script>
- Use the
blockUI()
andunblockUI()
methods in your JavaScript code to control the blocking overlay:
// Block the UI
$.blockUI({
message: '<h1>Please wait...</h1>',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: 0.5,
color: '#fff'
}
});
// Unblock the UI
$.unblockUI();
That's it! You can now use the blockui
library to easily add and remove blocking overlays in your web application.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
BlockUI - Page or element overlay
Getting Started
Download either the production version or the development version of BlockUI.
In your web page:
<!-- include jQuery --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> <!-- include BlockUI --> <script src="http://path/to/your/copy/of/jquery.blockUI.js"></script> <script> // invoke blockUI as needed --> $(document).on('click', '#myButton', function() { $.blockUI(); }); ></script>
Documentation, Demos and FAQ
Everything you need to know can be found here: http://jquery.malsup.com/block/
Copyright and License
Copyright © 2007-2013 M. Alsup.
The BlockUI plugin is dual licensed under the MIT and GPL licenses.
You may use either license. The MIT license is recommended for most projects because it is simple and easy to understand and it places almost no restrictions on what you can do with the plugin.
If the GPL suits your project better you are also free to use the plugin under that license.
You do not have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. You are free to use the BlockUI plugin in commercial projects as long as the copyright header is left intact.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot