kute.js/README.md

198 lines
10 KiB
Markdown
Raw Normal View History

2015-10-30 07:18:39 +01:00
# KUTE.js
2016-03-23 14:43:00 +01:00
A minimal <b>native Javascript</b> animation engine with <b>jQuery</b> plugin, with most essential features for web developers, designers and animators, delivering easy to use methods to set up high performance, cross-browser animations.
2015-05-21 17:31:07 +02:00
2016-03-23 14:20:11 +01:00
# Demo / CDN
For documentation, examples and other cool tips, check the <a href="http://thednp.github.io/kute.js/">demo</a>. Thanks to jsdelivr, we have a CDN link <a target="_blank" href="http://www.jsdelivr.com/#!kute.js">here</a>. We also have cdnjs link <a href="https://cdnjs.com/libraries/kute.js" target="_blank">right here</a>. Sweet!
2016-03-23 14:20:11 +01:00
# Core Engine - [visit page](http://thednp.github.io/kute.js/examples.html)
* tween object methods: `.to()`, `.fromTo()`, `.allTo()`, `.allFromTo()`
2016-03-23 14:24:58 +01:00
* tween control methods: `.start()`, `.stop()`, `.pause()`, `.play()`
2016-03-23 14:20:11 +01:00
* 2D and 3D transforms: all except `matrix`, `matrix3d`, `scale3d`, `rotate3d`
* box model properties: `top`, `left`, `width`, `height`
* colors: `color`, `backgroundColor`
* scroll: vertical scroll animation for `window` or any element with `overflow: auto|scroll`
2016-03-23 14:24:58 +01:00
* options: `yoyo`, `duration`, `easing`, `repeat`, `delay`, `offset` (for tween collections), `repeatDelay` and other transform/plugins related options
2016-03-23 14:20:11 +01:00
* Robert Penner's easing functions
* extensible prototypes and utility methods
# SVG Plugin - [visit page](http://thednp.github.io/kute.js/svg.html)
* morphs SVGs with the `path` tween property, updating the `d` attribute of `<path>` or `<glyph>` elements
2016-08-22 16:26:14 +02:00
* crows-browser SVG `transform` via the `svgTransform` property and the `transform` presentation attribute
2016-03-23 14:20:11 +01:00
* draws SVGs with the `draw` tween property for `<path>` elements
* SVG related color CSS properties such as: `fill`, `stroke`, `stopColor`
* other SVG CSS properties: `strokeWidth`, `stopOpacity`
# CSS Plugin - [visit page](http://thednp.github.io/kute.js/css.html)
2016-03-24 11:57:02 +01:00
* all box model properties: `margin`, `padding`, with all their variations like `marginTop`, all variations for `width` or `height` like `maxHeight` or `minWidth`, `outlineWidth`, `borderWidth` with all side variations, except short-hand notations
2016-03-23 14:20:11 +01:00
* `borderRadius` properties radius
2016-03-24 11:57:02 +01:00
* color properties: `outlineColor`, `borderColor` with all side variations except shorthands, etc
*`clip` property only for `rect` type of values
* text properties: `fontSize`, `lineHeight`, `lettersSpacing` and `wordSpacing`
2016-03-23 14:20:11 +01:00
# Text Plugin - [visit page](http://thednp.github.io/kute.js/text.html)
* animated number increments/decreases
* writing text with a cool effect
# Attributes Plugin - [visit page](http://thednp.github.io/kute.js/attr.html)
* animates any numeric presentation attribute with suffixed value
* animates any other non-suffixed numeric presentation attribute
# Easing Functions - [visit page](http://thednp.github.io/kute.js/easing.html)
* optimized dynamics easing functions
2016-03-24 11:57:02 +01:00
* optimized cubic-bezier easing functions
2016-03-23 14:20:11 +01:00
# jQuery Plugin
2016-03-24 21:49:22 +01:00
This aims to make the KUTE.js script work native within other jQuery apps but it's not always really needed as we will see in the second subchapter here. Since the demos don't insist on this particular plugin, we'll write some basics [right here](https://github.com/thednp/kute.js#using-the-jquery-plugin).
2016-03-23 14:20:11 +01:00
2016-03-24 21:46:59 +01:00
The plugin is just a few bits of code to bridge all of the the awesome `kute.js` methods to your jQuery apps. The plugin can be found in the [/master](https://github.com/thednp/kute.js/blob/master/kute-jquery.js) folder.
2016-03-23 14:20:11 +01:00
# NPM/Bower
You can install this through NPM or bower respectively:
2015-11-02 10:58:02 +01:00
```
$ npm install kute.js
# or
$ bower install kute.js
2015-05-21 17:30:41 +02:00
```
2015-04-15 21:34:07 +02:00
# CommonJS/AMD support
You can use this module through any of the common javascript module systems. For instance:
```javascript
2016-03-18 18:13:28 +01:00
// CommonJS style
//grab the core
var kute = require("kute.js");
2016-03-18 18:13:28 +01:00
// Add SVG Plugin
require("kute.js/kute-svg");
// Add CSS Plugin
require("kute.js/kute-css");
// Add Attributes Plugin
require("kute.js/kute-attr");
// Add Text Plugin
require("kute.js/kute-text");
2015-11-02 10:58:02 +01:00
// Add Bezier Easing
require("kute.js/kute-bezier");
2015-11-02 10:58:02 +01:00
// Add Physics Easing
require("kute.js/kute-physics");
2016-03-18 18:13:28 +01:00
// AMD style
define([
2016-03-18 18:13:28 +01:00
"kute.js", // core engine
"kute.js/kute-jquery.js", // optional for jQuery apps
2016-03-18 18:13:28 +01:00
"kute.js/kute-svg.js", // optional for SVG morph, draw and other SVG related CSS
"kute.js/kute-css.js", // optional for additional CSS properties
"kute.js/kute-attr.js", // optional for animating presentation attributes
"kute.js/kute-text.js" // optional for string write and number incrementing animations
"kute.js/kute-bezier.js", // optional for more accurate easing functions
"kute.js/kute-physics.js" // optional for more flexible & accurate easing functions
], function(KUTE){
// ...
});
```
2015-04-15 21:34:07 +02:00
2015-11-02 10:58:02 +01:00
# Basic Usage
At a glance, you can write one line and you're done.
```javascript
//vanilla js
KUTE.fromTo('selector', fromValues, toValues, options).start();
2015-11-02 10:58:02 +01:00
//with jQuery plugin
var tween = $('selector').KUTE('fromTo', fromValues, toValues, options);
$(tween).KUTE('start');
2015-11-02 10:58:02 +01:00
```
2015-04-15 21:34:07 +02:00
# Advanced Usage
2015-04-15 23:01:06 +02:00
Quite easily, you can write 'bit more lines and you're making the earth go round.
2015-10-30 07:06:11 +01:00
```javascript
2015-10-30 07:18:39 +01:00
//vanilla js is always the coolest
KUTE.fromTo(el,
{ translate: 0, opacity: 1 }, // fromValues
{ translate: 150, opacity: 0 }, // toValues
// tween options object
{ duration: 500, delay: 0, easing : 'exponentialInOut', // basic options
// callbacks
start: functionOne, // run function when tween starts
complete: functionTwo, // run function when tween animation is finished
update: functionThree // run function while tween running
stop: functionThree // run function when tween stopped
pause: functionThree // run function when tween paused
resume: functionThree // run function when resuming tween
}
).start(); // this is to start animation right away
```
2016-03-24 21:45:53 +01:00
## Using the jQuery Plugin
Here's a KUTE.js jQuery Plugin example that showcases most common usage in future apps:
```javascript
// first we define the object(s)
var tween = $('selector').KUTE('fromTo', // apply fromTo() method to selector
{ translate: 0, opacity: 1 }, // fromValues
{ translate: 150, opacity: 0 }, // toValues
// tween options object
{ duration: 500, delay: 0, easing : 'exponentialInOut', // basic options
//callbacks
start: functionOne, // run function when tween starts
complete: functionTwo, // run function when tween animation is finished
update: functionThree // run function while tween running
stop: functionThree // run function when tween stopped
pause: functionThree // run function when tween paused
resume: functionThree // run function when resuming tween
}
);
// then we apply the tween control methods, like start
$(tween).KUTE('start');
```
## Alternative usage in jQuery powered applications
2016-03-24 21:54:06 +01:00
When size matters, you can handle animations inside jQuery applications without the plugin. Here's how:
2016-03-24 21:45:53 +01:00
```javascript
var tween = KUTE.fromTo($('selector')[0], fromValues, toValues, options);
2016-03-24 21:54:06 +01:00
// or simply provide a class|id selector, just like the usual
var tween = KUTE.fromTo('#myElement', fromValues, toValues, options);
2016-03-24 21:45:53 +01:00
tween.start();
```
2016-03-24 21:54:06 +01:00
Pay attention to that `$('selector')[0]` as jQuery always creates an array of selected objects and not a single object, that is why we need to target a single HTML object for out tween object and not a colection of objects.
HTMLCollection objects should be handled with `allFromTo()` or `allTo()` methods.
2016-03-24 21:45:53 +01:00
```javascript
var tween = KUTE.allFromTo($('selector'), fromValues, toValues, options);
tween.start();
```
# How it works
* it computes all the values before starting the animation, then caches them to avoid layout thrashing that occur during animation
2015-12-30 17:23:16 +01:00
* handles all kinds of `transform` properties and makes sure to always use the same order of the `transform` properties (`translate`, `rotate`, `skew`, `scale`)
2015-12-30 22:04:39 +01:00
* allows you to set `perspective` for an element or it's parent for 3D transforms
2015-10-30 07:04:38 +01:00
* computes properties' values properly according to their measurement unit (px,%,deg,etc)
2015-10-30 07:18:39 +01:00
* properly handles cross browser 3D `transform` with `perspective` and `perspective-origin` for element or it's parent
* converts `HEX` colors to `RGB` and tweens the numeric values, then ALWAYS updates color via `RGB`
* properly replaces `top`, `centered` or any other background position with proper value to be able to tween
2015-10-18 17:52:36 +02:00
* for most supported properties it reads the current element computed style property value as initial value (via `currentStyle || getComputedStyle`)
2015-10-30 07:28:08 +01:00
* because it can read properties values from previous tween animations, KUTE.js can do some awesome chaining with it's `.to()` method
2015-10-18 17:52:36 +02:00
* allows you to add many callbacks: `start`, `update`, `complete`, `pause`, `stop`, and they can be set as tween options
2015-10-30 07:18:39 +01:00
* since `translate3D` is best for movement animation performance, `kute.js` will always use it
* accepts "nice & easy string" easing functions, like `linear` or `easingExponentialOut` (removes the use of the evil `eval`, making development safer, easier and closer to standards :)
2015-10-30 07:04:38 +01:00
* uses all 31 Robert Penner's easing functions, as well as bezier and physics easing functions
* handles browser prefixes for you for `transform`, `perspective`, `perspective-origin`, `border-radius` and `requestAnimationFrame`
* all this is possible with a core script of less than 20k size!
2015-04-15 21:34:07 +02:00
2015-04-15 22:08:56 +02:00
# Browser Support
2015-10-30 07:18:39 +01:00
Since most modern browsers can handle pretty much everything, legacy browsers need some help, so give them <a href="https://cdn.polyfill.io/v2/docs/">polyfills</a>. I also packed a small polyfill set with most essential features required by KUTE.js to work, it's called [minifill](https://github.com/thednp/minifill), try it.
2015-04-15 21:34:07 +02:00
2015-10-30 07:04:38 +01:00
# Contributions
2015-10-30 07:18:39 +01:00
* Dav aka [@dalisoft](https://github.com/dalisoft) contributed a great deal for the performance and functionality of KUTE.js
2015-10-30 07:04:38 +01:00
* [Ingwie Phoenix](https://github.com/IngwiePhoenix): RequireJS/CommonJS compatibility and usability with common package managers
* Others who [contribute](https://github.com/thednp/kute.js/graphs/contributors) to the project
2015-04-15 21:34:07 +02:00
# License
<a href="https://github.com/thednp/kute.js/blob/master/LICENSE">MIT License</a>