Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andycall/calculagraph
multifunctional calculagraph (多功能计时器)
https://github.com/andycall/calculagraph
Last synced: 6 days ago
JSON representation
multifunctional calculagraph (多功能计时器)
- Host: GitHub
- URL: https://github.com/andycall/calculagraph
- Owner: andycall
- Created: 2015-04-04T02:36:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-26T05:32:29.000Z (over 9 years ago)
- Last Synced: 2024-04-26T13:03:06.447Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 177 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Calculagraph
多功能计时器Here is an [English edition](README_US.md)
##安装
```bash
npm install calculagraph
```## 使用
### 准备
+ Node.js
```javascript
var Calculagraph = require('calculagraph');
```+ Browser Global
```javascript
console.log(Calculagraph);
```+ RequireJS
```javascript
define(['Calculagraph'], function(Calculagraph){
console.log(Calculagraph);
});
```
### Step 1: 构建time对象```javascript
var time = new Calculagraph();
```### Step 2: 设置起始时间
如果没有设置, 则默认为0。 当起始时间为0的时候, 逆时计时会自动停止。```javascript
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
### 逆时计时
```javascript
var time = new Calculagraph();
time.set(30);
time.decrease(function(time){
console.log(time);
}, 30, 500, function(){
console.log('finishde');
});```
### 顺时计时
``` javascriptvar time = new Calculagraph();
time.set(15);
time.increase(function(time){
console.log(time);
}, 20, 1000, function(){
console.log('finished');
});```
## 当前用户
* 阿里妈妈MUX:[http://mux.alimama.com/event/2015mothersday/index.html](http://mux.alimama.com/event/2015mothersday/index.html)