Coder Social home page Coder Social logo

timer-bar's Introduction

TimerBar JS

Introduction

TimerBar JS brings a visual and minimalist way to put a timer in your website. It is simple, lightweight and easy to use.

Basic usage

const fancyTimerBar = new TimerBar(myElement, myOptions);
fancyTimerBar.trigger();

Options

You might easily customize your TimerBar through its options.

It can either be passed in the constructor like this:

const fancyTimerBar = new TimerBar(myElement, {
    mode: "fill",
    anchor: "bottom",
    height: "50px",
    width: "10px",
});

Or after, accessing the properties directly:

const fancyTimerBar = new TimerBar(myElement);
fancyTimerBar.mode = "fill";
fancyTimerBar.anchor = "bottom";
fancyTimerBar.height = "50px";
fancyTimerBar.width = "10px";

Styling

  • width - Sets the width of the TimerBar. It comports all CSS units, like px and em. Integer values like 100 will not work.

  • height - Works in the same way as the width property.

  • barBackground - Sets the color of the animated bar. It is supported any CSS background definitions such as plain colors, gradients and images.

  • background - Change the background of the container likewise the barBackground option.

Behavior

  • mode - Defines the main behavior of the TimerBar. It can be:

    • empty - Starts filled and empties out.
    • fill - Starts empty and get filled.
  • anchor - Sets the anchor point of the animation, being possible the values: left, right, top and bottom

    For better understanding: A TimerBar with left anchor empties out to the left and gets filled from the left.

    Notice: when the anchor is left or right, the bar will have its width animated. If it is top or bottom, its height will be instead.

  • duration - Determine, in milisseconds, how long the animation will take.

  • delay - Delays the animation start and the finish event. To define the delay, it is necessary to pass an array whose first index sets the animationStartDelay and the second sets the finishDelay.

    Example: {delay: [200, 400]} - the animation starts after 200ms and the finish event is triggered 400ms later.

  • timingFunction - Set the timing function which the animation will operate on. All CSS timing-function types are supported.

Callback functions

{
    triggered: function() {
        console.log("I have been triggered!");
    }
}
  • triggered - Do something when the TimerBar starts to act, regardless of the delay.
  • finished - Do something when everything is done, even the finish delay.
  • started - [future implementation] - Do something when the animation starts, considering the delay.
  • ended - [future implementation] - Do something when the animation ends.
  • paused - [future implementation]
  • resumed - [future implementation]
  • reseted - [future implementation]

Notice: In the callback functions, the this keyword will be binded to the TimerBar instance. It's handy to use this.el to access the DOM element of it or even manipulate its options. Eg.: this.background = "#000".

Default values

Option Value
width "100%"
height "20px"
barBackground "#ccc"
background "#007bff"
mode "empty"
anchor "left"
duration 2000
delay [0, 0]
timingFunction "ease"

Events

  • trigger() - Starts the show!
  • reset() - Redefine the TimerBar to its initial state.
  • reverse() - Plays the contrary animation.
  • pause() - [future implementation]
  • resume() - [future implementation]

timer-bar's People

Contributors

camilomunhoz avatar

Watchers

 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.