Download
User Rating: 3.2/5 ( 2 votes)
Ladda is a javascript libraly that displays buttons with built-in loading indicators, effectively bridging the gap between action and feedback. Primarily intended for use with forms where it gives users immediate feedback upon submit rather than leaving them wondering while the browser does its thing.
Source: lab.hakim.se
1. INCLUDE CSS AND JS FILES
<link rel="stylesheet" href="dist/ladda.min.css">
<script src="dist/spin.min.js"></script>
<script src="dist/ladda.min.js"></script>
2. HTML
Ladda buttons must be given the class ladda-button and the button label needs to have the ladda-label class. The ladda-label will be automatically created if it does not exist in the DOM. Below is an example of a button which will use the expand-right animation style.
<section class="button-demo">
<h3>expand-up</h3>
<button class="ladda-button" data-color="green" data-style="expand-up">Submit</button>
</section>
Buttons accepts three attributes:
-
data-style: one of the button stylesi
-
data-color: green/red/blue/purple/mint
-
data-size: xs/s/l/xl, defaults to medium
-
data-spinner-size: 40, pixel dimensions of spinner, defaults to dynamic size based on the button height
-
data-spinner-color: A hex code or any named CSS color.
3. JAVASCRIPT
// Bind normal buttons
Ladda.bind( '.button-demo button', { timeout: 2000 } );
If you want JavaScript control over your buttons you can use the following approach:
// Create a new instance of ladda for the specified button
var l = Ladda.create( document.querySelector( '.my-button' ) );
// Start loading
l.start();
// Will display a progress bar for 50% of the button width
l.setProgress( 0.5 );
// Stop loading
l.stop();
// Toggle between loading/not loading states
l.toggle();
// Check the current state
l.isLoading();
// Delete the button's ladda instance
l.remove();
All loading animations on the page can be stopped by using: