dynamic tweening engine using exponential smoothing
$ component install threepointone/twain
from examples/basic.html
var box = document.getElementById('box'),
tween = Twain(); // start up a new tweener
tween.update(function(step) {
// step.left, step.top have values to be set
for(var prop in step){
box.style[prop] = step[prop] + 'px';
}
// or if you had jquery, you could do -
// $(box).css(step);
});
// update targets with every mousemove
document.body.addEventListener('mousemove', function(e) {
tween.to({
left: e.clientX,
top: e.clientY
});
});
setInterval(function(){
tween.update();
}, 1000/60)
Install dependencies with
npm install
then run
npm test
npm run-script coverage
MIT