Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calculagraph

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculagraph

multifunctional calculagraph, support Node.js, Browser and RequireJS

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Calculagraph

多功能计时器

Here is an English edition

##安装

npm install calculagraph

使用

准备

  • Node.js

    var Calculagraph = require('calculagraph');
    
  • Browser Global

    console.log(Calculagraph);
    
  • RequireJS

    define(['Calculagraph'], function(Calculagraph){
        console.log(Calculagraph);
    });
    

Step 1: 构建time对象


var time = new Calculagraph();
 

Step 2: 设置起始时间

如果没有设置, 则默认为0。 当起始时间为0的时候, 逆时计时会自动停止。


time.set(20); // 设置起始时间为20秒

Step 3: 绑定计时器

可以看下面的例子

API

increase 递增计时绑定

  • 参数:
    • callback 每一个时刻触发的回调函数
    • interval 总运行时间
    • tick 每一个时刻的时间间隔
    • finish 完成之后触发的回调函数

descrease 递减计时绑定

  • 参数:
    • callback 每一个时刻触发的回调函数
    • interval 总运行时间
    • tick 每一个时刻的时间间隔
    • finish 完成之后触发的回调函数

set 设置起始的时间, 需要在调用decrease或者increase时运行

  • 参数:
    • time : 设置的时间, 单位是秒

stop 停止计时, 同时清空计时状态。

parse 暂停计时, 保留计时状态

restore 恢复上一次暂停时的计时状态

restart 重启计时,如果之前设置了起始时间, 则从起始时间开始运行。

AMD 加载器支持

若检测到AMD加载器,暴露Calculagraph构造函数,且不再将Calculagraph暴露到全局下

Example

逆时计时

    
var time = new Calculagraph();
time.set(30);
time.decrease(function(time){
    console.log(time);
}, 30, 500, function(){
    console.log('finishde');
});

顺时计时


var time = new Calculagraph();
time.set(15);
time.increase(function(time){
    console.log(time);
}, 20, 1000, function(){
    console.log('finished');
});

当前用户

Keywords

FAQs

Package last updated on 26 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc