Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
animate-prop
Advanced tools
Single, dependency-free function to tween a property. Use that on canvas or anywhere else.
Single, dependency-free function to tween a property. Use that on canvas or anywhere else.
This is a very simple and low-level function tween/animate/update a value over time. If you're looking for something that updates DOM elements directly, try the excellent but 60 times heavier TweenLite (+its CSS Plugin).
Originally from the article "Animation with HTML5 Canvas", where you can see more examples.
// We'll animate the property x, starting from 5
var obj = { x: 5 };
// 10 is the final value that the property x will have after 1000 milliseconds
animateProp(obj, 'x', 10, 1000);
// use the object in your drawing loop
context.moveTo(obj.x, 100);
setInterval(function () {
// progressively draw a line
context.lineTo(obj.x, 100);
context.stroke();
}, 16); // don't use setInterval, it's just an example
You can provide an easing function
// see https://github.com/jaz303/easiness/blob/master/raw.js
var easeInOutSine = function (progress) {
return Math.sin(Math.PI/2 * progress);
};
var obj2 = { scale: 1 };
animateProp(obj2, 'scale', 2, 300, easeInOutSine, function () {
console.log('Eased animation done!')
});
Or just wait for it to be done, without an easing
var obj3 = { opacity: 0 }; // v--- easing:false = linear tween
animateProp(obj3, 'opacity', 0.5, 300, false, function () {
console.log('Linear animation done!')
});
Animate multiple properties with any duration
var obj = { x: 5, y: 100 };
animateProp(obj, 'x', 10, 1000);
animateProp(obj, 'y', 300, 500);
Sequence tweens
var obj = { x: 5, y: 100 };
animateProp(obj, 'x', 10, 1000, function () {
animateProp(obj, 'y', 300, 500);
});
npm install --save animate-prop
var animateProp = require('animate-prop');
animateProp(object, propertyName, finalValue, duration[, easing[, callback]])
parameter | description |
---|---|
object | Type: object , required The object with the property to tween |
propertyName | Type: string , required The property key to animate (e.g. 'height') |
finalValue | Type: number , required The final value that the property will have |
duration | Type: number , required The duration of the tween |
easing | Type: function or boolean , default: linear Given a number from 0 to 1, returns an eased number from 0 to 1 (optional) |
callback | Type: function , default: none Function to be called when the tween is over (optional) |
Here's an explanation of the files included in this repo
index.js
: source file, in ES6dist/animate-prop.js
: browser-ready file with AMD or a global variable called animateProp
dist/animate-prop.min.js
: same as above, minifieddist/animate-prop.node.js
: used by node/browserify with require('animate-prop')
dist/animate-prop.node.min.js
: same as above, but minified, for byte counting onlyNo dependencies, but it needs window.requestAnimationFrame
to be there (IE10+ or with polyfill)
Easing functions are not included. Provide your own or use easiness
MIT © Federico Brigante
FAQs
Single, dependency-free function to tween a property. Use that on canvas or anywhere else.
We found that animate-prop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.