1.0.17 • Published 6 years ago

project-simple-red-timer v1.0.17

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

RedTimer

Simple Javascript Timer

License: MIT

NPM

github - here

Install

npm

npm install project-simple-red-timer --save-dev
import RedTimer from 'project-simple-red-timer';

browser

<script src="https://project-simple.github.io/RedTimer/dist/RedTimer.min.js"></script>
<script>
    RedTimer(
        'testKey_1',
        1000,
        function(){}, 
        function(){}
    );
</script>

API

RedTimer(key, duration, updateCallback, endCallback)

paramdescriptiontype
keyunique keystring
durationtimer durationpositive number(Millisecond)
updateCallbackRegister a function to be called whenever the timer is updated.function or undefined
endCallbackRegister a function to be called when the timer is end.function or undefined
    var t0 = RedTimer('testKey_1',1000,function(){}, function(){});
    var t1 = new RedTimer('testKey_2',1000,function(){}, function(){});
    console.log(t0 instanceof RedTimer); // true
    console.log(t1 instanceof RedTimer); // auto call constructor

property

namedescriptionread/writetype
keyTimer keyread-onlystring
durationTimer durationread/writepositive number(Millisecond)
startTimeTimer startTimeread-onlynumber(Millisecond)
endTimeTimer endTimeread-onlynumber(Millisecond)
elapsedTimeTimer elapsedTimeread-onlynumber(Millisecond)
remainTimeTimer remainTimeread-onlynumber(Millisecond)
    RedTimer(
        'testKey_1',
        1000,
        function(){
            console.log('key', this.key); 
            console.log('duration', this.duration);
            console.log('startTime', this.startTime);
            console.log('endTime', this.endTime);
            console.log('elapsedTime', this.elapsedTime);
            console.log('remainTime', this.remainTime);
            console.log('//////////////////////') 
        }, 
        function(){}
    );

method

  • (RedTimer Instance).destroy()

    var t0 = RedTimer('testDestroy',1000,function(){},function(){})
    t0.destroy();
  • Target timer destroyed immediately (endCallback not called)

static method

  • RedTimer.destroyAll()

    RedTimer( 'testDestroyAll_1', 1000, function(){}, function(){} );
    RedTimer( 'testDestroyAll_2', 2000, function(){}, function(){} );
    RedTimer( 'testDestroyAll_3', 3000, function(){}, function(){} );
    RedTimer( 'testDestroyAll_4', 4000, function(){}, function(){} );
    RedTimer.destroyAll();
  • Destroys the currently active RedTimer instance. (endCallback not called)

TestCase

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago