Ladda

Buttons with built-in loading indicators.

  • 所有者: hakimel/Ladda
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Ladda

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

Check out the demo page.

Installation

npm install ladda

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

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 using the expand-right animation style.

<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
  • 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.

Note: Ladda 2.x is distributed as an ES6 module, but not all browsers support importing native ES6 modules.
For full browser compatibility, use a module bundler such as Webpack
or Rollup to create a production-ready code bundle.

Changelog

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

License

MIT

主要指標

概覽
名稱與所有者hakimel/Ladda
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2013-06-05 08:30:13
推送於2021-12-02 21:28:53
最后一次提交2021-12-02 15:21:21
發布數32
最新版本名稱2.0.3 (發布於 2021-12-02 15:28:51)
第一版名稱0.1.0 (發布於 )
用户参与
星數7.8k
關注者數203
派生數858
提交數209
已啟用問題?
問題數51
打開的問題數8
拉請求數34
打開的拉請求數1
關閉的拉請求數19
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?