Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/component/tween
Motion tween engine using "ease"
https://github.com/component/tween
Last synced: 12 days ago
JSON representation
Motion tween engine using "ease"
- Host: GitHub
- URL: https://github.com/component/tween
- Owner: component
- Created: 2012-10-28T09:35:32.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-03-16T21:27:43.000Z (almost 10 years ago)
- Last Synced: 2024-12-11T23:34:45.330Z (16 days ago)
- Language: HTML
- Size: 262 KB
- Stars: 36
- Watchers: 9
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# tween
Motion tween component using [ease](https://github.com/component/ease).
## Installation
$ component install component/tween
## Example
```js
var Tween = require('tween');
var raf = require('raf');
var button = document.querySelector('button');var tween = Tween({ rotate: 0, opacity: 0 })
.ease('out-bounce')
.to({ rotate: 360, opacity: 1 })
.duration(800);tween.update(function(o){
button.style.opacity = o.opacity;
button.style.webkitTransform = 'rotate(' + (o.rotate | 0) + 'deg)';
});tween.on('end', function(){
animate = function(){};
});function animate() {
raf(animate);
tween.update();
}animate();
```## API
### Tween(obj:Object|Array)
Initialize a new `Tween` with `obj`.
### Tween#reset()
Reset the tween.
### Tween#to(obj:Object|Array)
Tween to `obj` and reset internal state.
tween.to({ x: 50, y: 100 })
### Tween#duration(ms:Number)
Set duration to `ms` [500].
### Tween#ease(fn:String|Function)
Set easing function to `fn`.
tween.ease('in-out-sine')
### Tween#update(fn:Function)
Set update function to `fn` or
when no argument is given this performs
a "step".### Tween#stop()
Immediately stop the tween and emit "stop" and end" events. `tween.stopped`
is then marked as `true`.## License
MIT