Convert Figma logo to code with AI

hakimel logoLadda

Buttons with built-in loading indicators.

7,851
872
7,851
9

Top Related Projects

11,942

📝 the simplest and smallest WYSIWYG text editor for web, with no dependencies

19,349

A collection of loading indicators animated with CSS

29,203

A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.

Delightful, performance-focused pure css loading animations.

15,677

Automatically add a progress bar to your site.

Quick Overview

Ladda is a UI concept for buttons which merges loading indicators into the action that invoked them. It provides a smooth, unobtrusive loading animation directly within the button, enhancing user experience during asynchronous operations.

Pros

  • Improves user interface by providing visual feedback without disrupting layout
  • Easy to implement with minimal setup required
  • Customizable with various styles and animations
  • Works well with modern web frameworks and vanilla JavaScript

Cons

  • Limited to button elements, not applicable to other UI components
  • May not be suitable for complex loading scenarios or multi-step processes
  • Requires additional JavaScript, which might increase page load time slightly
  • Some animations may be too subtle for users to notice on certain devices or screen sizes

Code Examples

  1. Basic usage with a button:
<button class="ladda-button" data-style="expand-right">
  <span class="ladda-label">Submit</span>
</button>
  1. JavaScript initialization:
var button = document.querySelector('.ladda-button');
var l = Ladda.create(button);

button.addEventListener('click', function() {
  l.start();
  // Perform async operation here
  setTimeout(function() {
    l.stop();
  }, 2000);
});
  1. Angular directive usage:
<button ladda="isLoading" data-style="expand-right" class="ladda-button" ng-click="submitForm()">
  Submit
</button>

Getting Started

  1. Include Ladda's CSS and JavaScript files in your HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Ladda/1.0.6/ladda.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Ladda/1.0.6/ladda.min.js"></script>
  1. Add the Ladda button markup to your HTML:
<button class="ladda-button" data-style="expand-right">
  <span class="ladda-label">Submit</span>
</button>
  1. Initialize Ladda in your JavaScript:
var button = document.querySelector('.ladda-button');
var l = Ladda.create(button);

button.addEventListener('click', function() {
  l.start();
  // Perform your async operation here
  setTimeout(function() {
    l.stop();
  }, 2000);
});

This setup creates a button with the Ladda loading animation that starts when clicked and stops after 2 seconds. Adjust the timeout or replace it with your actual asynchronous operation.

Competitor Comparisons

11,942

📝 the simplest and smallest WYSIWYG text editor for web, with no dependencies

Pros of Pell

  • Lightweight and dependency-free WYSIWYG text editor
  • Simple API and easy integration into web applications
  • Customizable toolbar with essential formatting options

Cons of Pell

  • Limited features compared to more robust text editors
  • Lacks advanced formatting options and plugins
  • May require additional development for complex use cases

Code Comparison

Pell initialization:

const editor = pell.init({
  element: document.getElementById('editor'),
  onChange: html => {
    // Handle changes
  }
})

Ladda button creation:

const button = document.querySelector('button');
const l = Ladda.create(button);
l.start();
setTimeout(() => l.stop(), 2000);

Summary

Pell is a lightweight WYSIWYG text editor, while Ladda is a UI component for loading indicators on buttons. They serve different purposes, making a direct comparison challenging. Pell offers a simple text editing solution, whereas Ladda enhances button interactions with loading animations. The choice between them depends on the specific needs of your project - text editing functionality or improved button feedback.

19,349

A collection of loading indicators animated with CSS

Pros of SpinKit

  • Offers a wider variety of loading animations (9 different styles)
  • Pure CSS-based animations, reducing JavaScript dependencies
  • Easier to customize and integrate into existing projects

Cons of SpinKit

  • Lacks built-in button integration, unlike Ladda's button-focused approach
  • Does not provide progress indication functionality
  • May require more manual styling to fit specific design requirements

Code Comparison

SpinKit (CSS):

.spinner {
  width: 40px;
  height: 40px;
  background-color: #333;
  margin: 100px auto;
  -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
  animation: sk-rotateplane 1.2s infinite ease-in-out;
}

Ladda (HTML + JavaScript):

<button class="ladda-button" data-style="expand-right">
  <span class="ladda-label">Submit</span>
</button>
<script>
  Ladda.bind('button', { timeout: 2000 });
</script>

SpinKit focuses on pure CSS animations for various loading indicators, while Ladda specializes in button-integrated loading animations with progress indication. SpinKit offers more versatility in animation styles, but Ladda provides a more comprehensive solution for interactive buttons with built-in loading states.

29,203

A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.

Pros of Hover

  • Offers a wider variety of CSS effects and transitions
  • Easier to implement for simple hover effects without JavaScript
  • Lightweight and purely CSS-based, reducing load times

Cons of Hover

  • Limited to hover interactions only, less versatile for other user actions
  • Lacks built-in loading state management
  • May require more custom code for complex animations or state changes

Code Comparison

Hover:

.hover-effect {
  display: inline-block;
  vertical-align: middle;
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  backface-visibility: hidden;
  transition-duration: 0.3s;
  transition-property: transform;
}

Ladda:

<button class="ladda-button" data-style="expand-right">
  <span class="ladda-label">Submit</span>
</button>

<script>
  Ladda.bind('button', { timeout: 2000 });
</script>

Hover focuses on pure CSS implementations for hover effects, making it simpler to use for basic interactions but less flexible for complex scenarios. Ladda, on the other hand, provides a more robust solution for button interactions, including loading states, but requires JavaScript and is more focused on form submissions and action feedback.

Delightful, performance-focused pure css loading animations.

Pros of loaders.css

  • Offers a wider variety of loader animations (over 30 different styles)
  • Pure CSS implementation, reducing JavaScript dependencies
  • Easier to customize and integrate into existing projects

Cons of loaders.css

  • Lacks built-in button integration, unlike Ladda's seamless button loading states
  • No built-in progress indication functionality
  • May require more manual setup for complex use cases

Code Comparison

Ladda (JavaScript):

var l = Ladda.create(document.querySelector('.my-button'));
l.start();
// Perform async operation
l.stop();

loaders.css (HTML/CSS):

<div class="loader-inner ball-pulse">
  <div></div>
  <div></div>
  <div></div>
</div>

Summary

loaders.css provides a diverse range of pure CSS loading animations, making it lightweight and easy to implement. However, it lacks the integrated button functionality and progress indication features of Ladda. Ladda offers a more comprehensive solution for button loading states but has a narrower focus on button-specific animations. The choice between the two depends on the specific requirements of the project, with loaders.css being more suitable for general-purpose loading animations and Ladda excelling in button-centric loading scenarios.

15,677

Automatically add a progress bar to your site.

Pros of pace

  • Automatic progress tracking without manual updates
  • Works with various types of page loads (AJAX, pushState)
  • Customizable themes and colors

Cons of pace

  • Can be intrusive on fast-loading pages
  • May not accurately represent actual loading progress
  • Limited control over progress indication behavior

Code Comparison

Ladda (button with loading indicator):

<button class="ladda-button" data-style="expand-right">
  <span class="ladda-label">Submit</span>
</button>

pace (automatic progress bar):

<!-- No explicit code needed in HTML -->
<script src="pace.min.js"></script>

Key Differences

  • Ladda focuses on button loading indicators, while pace provides a global page loading progress bar
  • Ladda requires manual control, pace operates automatically
  • Ladda offers more granular control over individual elements, pace affects the entire page

Use Cases

  • Ladda: Form submissions, action buttons, user-triggered operations
  • pace: Overall page load progress, single-page applications, AJAX-heavy sites

Community and Maintenance

  • Ladda: Less active development, stable for its specific use case
  • pace: More active community, broader application, but potential for conflicts with other scripts

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Ladda

Buttons with built-in loading indicators, effectively bridging the gap between action and feedback.

Check out the demo page.

Installation

npm install ladda

Module bundling

Ladda 2.x is distributed as a standard ES6 module. Since not all browsers/environments support native ES6 modules, it is recommended to use a bundler such as Rollup, Parcel, or Webpack to create a production-ready code bundle.

Usage

CSS

You will need to include ONE of the two style sheets in the /dist directory. If you want the button styles used on the demo page, use the ladda.min.css file. If you want to have the functional buttons without the visual style (colors, padding, etc.), use the ladda-themeless.min.css file.

HTML

Below is an example of a button using the expand-right animation style.

<button class="ladda-button" data-style="expand-right">Submit</button>

When the JS code runs to bind Ladda to the button, the ladda-button class will be automatically added if it doesn't already exist. Additionally, a span with class ladda-label will automatically wrap the button text, resulting in the following DOM structure:

<button class="ladda-button" data-style="expand-right">
    <span class="ladda-label">Submit</span>
</button>

Buttons accept the following attributes:

  • data-style: one of the button styles [required]
    • expand-left, expand-right, expand-up, expand-down
    • contract, contract-overlay
    • zoom-in, zoom-out
    • slide-left, slide-right, slide-up, slide-down
  • data-color: green/red/blue/purple/mint
  • data-size: xs/s/l/xl, defaults to medium
  • data-spinner-size: pixel dimensions of spinner, defaults to dynamic size based on the button height
  • data-spinner-color: a hex code or any named CSS color, defaults to #fff
  • data-spinner-lines: the number of lines for the spinner, defaults to 12

JavaScript

Start by importing the Ladda module:

import * as Ladda from 'ladda';

The following approach is recommended for JavaScript control over your buttons:

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

To show the loading animation for a form that is submitted to the server (always resulting in a page reload) the bind() method can be used:

// Automatically trigger the loading animation on click
Ladda.bind('button[type=submit]');

// Same as the above but automatically stops after two seconds
Ladda.bind('button[type=submit]', {timeout: 2000});

Note: when using the bind() method on buttons that are inside a form, loading indicators will not be shown until the form is valid.

All loading animations on the page can be stopped by using:

Ladda.stopAll();

Browser support

Ladda has been tested in Firefox, Microsoft Edge, Chrome, and Internet Explorer 11. It also Should Work™ in Safari and Internet Explorer 10.

Changelog

https://github.com/hakimel/Ladda/blob/master/CHANGELOG.md

License

MIT

NPM DownloadsLast 30 Days