instant-time
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

instant-time NPM version Build Status

Library for working with time and animations based on requestAnimationFrame

Installation

$ npm install --save instant-time

Usage

import inTime from 'instant-time'

Available methods inTime

inTime.Delay(handler: (timePassed: number) => void, delay?: number): number
inTime.Interval(handler: (timePassed: number) => (void | boolean), duration?: number): number
inTime.Animate(handler: (timePassed?: number) => void, duration?: number): number
inTime.Cancel(frameID?: number): void

Examples

inTime.Delay( () => {
    //Deferred function execution via 2000 milliseconds
    alert( 'after two seconds' )
}, 2000 )
inTime.Interval( () => {
    //Deferred function execution via every 2000 milliseconds
    alert( 'every two seconds' )
}, 2000 )
document.body.innerHTML = '<div id="rotate-block" style="width: 100px; height: 100px; background: #000000; position: relative"></div>'
inTime.Animate( (timePassed) => {
    //Moves the block to the left for two seconds
    document.getElementById('rotate-block').style.left = timePassed / 5 + 'px';
}, 2000 )
const alertHelloId = inTime.Interval( () => {
    alert( 'hello' )
}, 2000 )
inTime.Delay( () => {
    //Will turn off the interval after 6 seconds
    inTime.Cancel(alertHelloId)
}, 6000 )

License

MIT © LETWOLF, LTD

Package Sidebar

Install

npm i instant-time

Weekly Downloads

1

Version

1.0.4

License

MIT

Last publish

Collaborators

  • letwolf