Git Product home page Git Product logo

yisibell / trickling Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 441 KB

A modern progress bar for web APP. Featuring realistic trickle animations to convince your users that something is happening!

Home Page: https://hongwenqing.com/trickling/

License: MIT License

JavaScript 2.06% HTML 1.28% Vue 29.50% CSS 3.55% TypeScript 56.61% SCSS 7.00%
progress-bar trickle trickling modern web nprogress next-nprogress

trickling's Introduction


Trickling

A modern progress bar for web APP. Featuring realistic trickle animations to convince your users that something is happening!

Features

  • Support programmatically modify the style of the progress bar.
  • Support RTL languages.
  • Support Typescript.

Installation

# pnpm
$ pnpm add trickling

# yarn
$ yarn add trickling

# npm
$ npm i trickling

Usage

  1. Imports style.
import 'trickling/lib/style.css'
  1. Create a trickling progress instance in a single file.
// @/plugins/trickling-progress.ts

import { createTrickling } from 'trickling'

// Create a Trickling progress instance
const tricklingProgress = createTrickling({
  // Options
  // ...
})

// You can also change options after creating a Trickling progress instance
tricklingProgress.setOptions({
  // ...
})

// Export the instance
export { tricklingProgress }
  1. Using it where needed.
import { tricklingProgress } from '@/plugins/trickling-progress.ts'

// ...
// shows the Trickling progress bar
tricklingProgress.start()

// ...
// Then, completes the Trickling progress
tricklingProgress.done()

Options

Key Type Default value Description
minimum number 0.08 Changes the minimum percentage used upon starting.
maximum number 0.994 Changes the maximum percentage used upon ending.
easing string ease Adjust animation settings using easing (a CSS easing string).
speed number 200 Adjust animation settings using speed (in ms).
trickle boolean true Turn off the automatic incrementing behavior by setting this to false.
trickleSpeed number 1000 Adjust how often to trickle/increment (in ms).
showSpinner boolean true Turn off loading spinner by setting it to false.
appendTo string, HTMLElement body Specify this to change the parent container.
customWrapperClassName string '' Specify this to add a class name into the parent container.
color string #2299dd Specify this to change color of the progress bar and spinner.
progressBarHeight string 2px Specify this to change height of the progress bar.
spinnerOpacity number 1 Specify this to change opacity of the loading spinner.
spinnerSize string 18px Specify this to change size of the loading spinner.
spinnerStrokeWidth string 2px Specify this to change stroke width of the loading spinner.
rtl
(Added in v1.6.0)
boolean false Change the progress direction to right-to-left.
removeFromDOMWhenDone
(Added in v1.9.0)
boolean true Remove the component from the DOM when done, re-add when needed. This can have performance implications on complex apps as style calculations are slow. If set to false, just hidden the DOM via display: none when progress done.
zIndex
(Added in v1.8.0)
number/string 1031 Specify this to change progress bar z-index.
trickleIncrementalCurve
(Added in v1.10.0)
function/Array See below You can use this option to configure the incremental curve of the trickle.

Trickle Incremental Curve

Using this configuration allows you to easily change the default trickle increasing curve. Thus, each Progress bar has different incremental expressions.

  1. Default value
[
  { from: 0, to: 0.2, value: 0.1 },
  { from: 0.2, to: 0.5, value: 0.04 },
  { from: 0.5, to: 0.8, value: 0.02 },
  { from: 0.8, to: 0.99, value: 0.005 },
]
  • from: This represents the starting range of the current progress status (including).
  • to: This represents the end range of the current progress status (excluding).
  • value: This represents the progress increment value of the current range.
  1. Type definition see here.
  • Function: If you use it as a function, should returns a number or array.
  • Array: Just set it via a array.

Advanced usage

  1. Percentages: To set a progress percentage, call .set(n), where n is a number between 0..1.
trickling.set(0.0);     // Just same as .start()
trickling.set(0.4);
trickling.set(1.0);     // Just same as .done()
  1. Incrementing: To increment the progress bar, just use .inc(). This increments it with a random amount. This will never get to 100%: use it for every image load (or similar).
trickling.inc();
  1. If you want to increment by a specific value, you can pass that as a parameter:
trickling.inc(0.2);    // This will get the current status value and adds 0.2 until status is 0.994
  1. Force-done: By passing true to done(), it will show the progress bar even if it's not being shown. (The default behavior is that .done() will not do anything if .start() isn't called).
trickling.done(true);
  1. Get the status value: To get the status value, use .status.
trickling.status

trickling's People

Contributors

yisibell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.