Button Loading Animation in Bootstrap 4

Button Loading Animation in Bootstrap 4
Code Snippet:Bootstrap Button Loading
Author: jmalatia
Published: January 11, 2024
Last Updated: January 22, 2024
Downloads: 11,929
License: MIT
Edit Code online: View on CodePen
Read More

The “Button Loading” is a minimal code snippet to add a loader inside the Bootstrap 4 button. You can reveal loading animation on the JavaScript click event to inform the users about the processing of an operation.

How to Create Loading Animation in Bootstrap Button

1. First of all, load the Bootstrap and Font Awesome CSS by adding the following CDN links into the head section of your HTML page.

<!-- Bootstrap CSS -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>
<!-- Font Awesome CSS -->
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css'>

2. After that, create a button element with the following mentioned attributes.

<button type="button" class="btn btn-primary btn-lg " id="load1" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order">Submit Order</button>

4. Now, load the jQuery JavaScript library and Bootstrap JS just before the closing of body tag.

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- Bootstrap JS -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js'></script>

5. Finally, initialize the button loading animation on click event using the following JavaScript function.

$('.btn').on('click', function () {
	var $this = $(this);
	$this.button('loading');
	setTimeout(function () {
		$this.button('reset');
	}, 8000);
});

You’ve all done! I hope you have successfully created loading animation inside the Bootstrap 4 button. If you need any further help, let me know by comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X