<p>KUTE.js can be used in most cases with native Javascript, but also with jQuery. So, before we head over to the more advanced examples, let's have a quick look at these two basic examples here. <strong>Note</strong>: the examples are posted on <ahref="http://codepen.io/thednp/pens/public/"target="_blank">codepen</a>.</p>
<h3>Basic Native Javascript Example</h3>
<p>When developing with native Javascript, a very basic syntax goes like this:</p>
<pre>
<codeclass="language-javascript">// this is the tween object, basically KUTE.method(element, from, to, options);
var tween = KUTE.fromTo('selector', {left: 0}, {left: 100}, {yoyo: true});</code>
</pre>
<p>Now the tween object is created, it's a good time for you to know that via Native Javascript we <strong>always</strong> animate the first HTML element only, even if you're using a class selector. To create/control a tween for multiple elements such as <code>querySelectorAll()</code> or <code>getElementsByTagName()</code>, you need to do a <code>for ()</code> loop. Now let's apply the tween control methods:</p>
<pre><codeclass="language-javascript">tween.start(); // starts the animation
tween.stop(); // stops current tween and all chained tweens animating
tween.pause(); // pauses current tween animation
tween.play(); // or tween.resume(); resumes current tween animation
tween.chain(tween2); // when tween animation finished, you can trigger the start of another tween
</code></pre>
<p>The demo for the above example is <ahref="http://codepen.io/thednp/pen/Bozbgg"target="_blank">here</a>.</p>
<h3>Basic jQuery Example</h3>
<p>KUTE.js includes a jQuery plugin to help you easily implement KUTE.js in your jQuery applications. When using jQuery, the syntax is familiar but works a bit different than plain Javascript due to jQuery's specific code standards. Let's have a look:</p>
<pre><codeclass="language-javascript">// this is the tween object, basically $('selector').KUTE(method, from, to, options);
var tween = $('selector').KUTE('fromTo', {top: 20}, {top: 100}, {yoyo: true});
</code></pre>
<p>We mentioned that the KUTE jQuery plugin is different, and here's why: the above code creates an <code>Array</code> of objects for each <code>HTML</code> element of chosen selector, while the Native Javascript creates a single object. For these objects we can now apply the tween control methods as follows:</p>
<pre><codeclass="language-javascript">$(tween).KUTE('start'); // starts the animation
$(tween).KUTE('stop'); // stops current tween and all chained tweens animating
$(tween).KUTE('pause'); // pauses current tween animation
$(tween).KUTE('play'); // or $(myTween).KUTE('resume'); resumes current tween animation
$(tween).KUTE('chain',myTween2); // when tween animation finished, you can trigger the start of another tween
</code></pre>
<p>The demo for the above example is <ahref="http://codepen.io/thednp/pen/dYXLyj"target="_blank">here</a>.</p>
<h2>Transform Properties Examples</h2>
<p>KUTE.js supports almost all about <code>transform</code> as described in the <ahref="http://www.w3.org/TR/css3-transforms/"target="_blank">spec</a>: the 2D <code>translate</code>, <code>rotate</code>, <code>skewX</code>, <code>skewY</code> and <code>scale</code>, as well as the 3D <code>translateX</code>, <code>translateY</code>, <code>translateZ</code>, <code>translate3d</code>, <code>rotateX</code>, <code>rotateX</code>, <code>rotateY</code>, <code>rotateZ</code> properties. Additionally it allows you to set a <code>perspective</code> for the element or it's parent as well as a <code>perpective-origin</code> for the element or it's parent.</p>
<h3>Translations</h3>
<p>In the next example the first box is moving to left 250px with <code>translate</code> property, the second box is moving to the right by 200px using <code>translateX</code> and the third box is moving to the bottom using <code>translate3d</code>. The last box also uses <code>translate3d</code> but requires a <code>perspective</code> value for the animation on the Z axis to be effective.</p>
<pre><codeclass="language-javascript">var tween1 = KUTE.fromTo('selector1',{translate:0},{translate:-250}); // or translate:[x,y] for both axis
var tween2 = KUTE.fromTo('selector2',{translateX:0},{translateX:200});
var tween3 = KUTE.fromTo('selector3',{translate3d:[0,0,0]},{translate3d:[0,100,0]});
var tween4 = KUTE.fromTo('selector4',{translate3d:[0,0,0]},{translate3d:[0,0,-100]},{parentPerspective: 100});
<p>As you can see in your browsers console, for all animations <code>translate3d</code> is used, as explained in the <ahref="features.html">features page</a>. Also the first example that's using the 2D <code>translate</code> for both vertical and horizontal axis even if we only set X axis. You can download this example <ahref="http://codepen.io/thednp/share/zip/rOLbyY">here</a>.</p>
<p><strong>Remember</strong>: stacking <code>translate</code> and <code>translate3d</code> together may not work and IE9 does not support <code>perspective</code>.</p>
<h3>Rotations</h3>
<p>Next we're gonna animate 4 elements with one axis each element. Unlike translations, KUTE.js does not support <code>rotate3d</code>.</p>
<p>The <code>rotateX</code> and <code>rotateY</code> are 3D based rotations, so they require a perspective in order to make the browser render proper 3D layers, but in the example they animate different because only the second, Y axis, uses a <code>perspective</code> setting. The rotation on Z axis does not require a perspective. Unlike translations, you can stack all axis rotation for your animation, but we will see that in a later example. You can download this example <ahref="http://codepen.io/thednp/share/zip/NGrmMR">here</a>.</p>
<h3>Skews</h3>
<p>KUTE.js supports <code>skewX</code> and <code>skewY</code> so let's animate the two. Since they are 2D transformations, IE9 supports skews.</p>
<p>You can download this example <ahref='http://codepen.io/thednp/share/zip/wKWbKd/'>here</a>.</p>
<h3>Mixed Transformations</h3>
<p>The current specification does not support animating different transform properties with multiple tween objects at the same time, you must stack them all together into a single object. See the example below:</p>
var tween2 = KUTE.fromTo('selector1',{skewY:0},{skewY:45}).start();
</code></pre>
<p>If you check the <ahref="http://codepen.io/thednp/pen/avZrYo"target="_blank">test here</a>, you will notice that only the <code>skewY</code> is going to work and no rotation. Now let's do this properly.</p>
<p>Now you can see we are using the specific transform options, the first tween object uses these settings for an element and the second for its parent.</p>
<p>This example also shows the difference between an element's perspective and a parent's perspective. You can download the above example <ahref='http://codepen.io/thednp/share/zip/jbrovv/'>here</a>.</p>
<h3>Chained Transformations</h3>
<p>I'm gonna insist on the tween chaining feature a bit because when we run animations one after another we are kinda expecting a certain degree of continuity. As explained before, the best solution is the <code>.to()</code> method because it has the ability to <strong>stack</strong> properties found in the element's inline styling, mostly from previous tween animation, and use them as start values for the next tween. It also transfers unchanged values to values end for that same reason. OK now, let's see a side by side comparison with 3 elements:</p>
<li>the first box uses a regular <codeclass="bg-gray">.fromTo()</code> object, we are doing things normally, we would expect them to work properly but due to the nature of the transforms, this is what it does</li>
<li>the second box is also using <codeclass="bg-olive">.fromTo()</code> object, but using proper values for all tweens at all times, so we fixed that glitch</li>
<li>and the last box uses the <codeclass="bg-indigo">.to()</code> method, and does the chaining easier for most properties, especially for <code>transform</code></li>
</ul>
<p>When coding transformation chains I would highly recommend:</p>
<ul>
<li>keep the same order of the transform properties, best would be: translation, rotation, skew and scale; an example of the difference shown <ahref="http://jsfiddle.net/nvy26bgb/"target="_blank">here</a> for rotations and <ahref="http://jsfiddle.net/nvy26bgb/1/"target="_blank">here</a> for rotations and skew;</li>
<li>2D and 3D translations would work best in if you provide a value at all times; eg. <code>translate:[x,y]</code> and <code>translate3d:[x,y,z]</code>; for instance using <code>translate:150</code> or <code>translateX:150</code> would mean that all other axis are 0;</li>
<li>on larger amount of elements animating chains, the <code>.fromTo()</code> method is fastest, so you will have more work, but can potentially minimize or eliminate any syncronization issues that may occur, as explained in the <ahref="features.html">features page</a>;</li>
<li>download this example <ahref='http://codepen.io/thednp/share/zip/PPWZRL/'>here</a>.</li>
</ul>
<h2>Border Radius</h2>
<p>In the example below we are doing some animation on the <code>border-radius</code> property. The first box animates all corners, while the other boxes animate each corner at a time. A quick reminder, for radius properties KUTE.js supports <code>px</code>, <code>%</code> and text properties' units such as <code>em</code> or <code>rem</code>.</p>
<p>A quick important reminder here is that KUTE.js does not support shorthands for radius properties. Also early implementations by Mozilla's Firefox browser like <code>-moz-border-radius-topleft</code> are not supported because they were depracated with later versions. Download this example <ahref='http://codepen.io/thednp/share/zip/VvpypW/'>here</a>.</p>
<h2>Box Model Properties</h2>
<p>While KUTE.js supports almost all the box model properties, the next example will animate most common properties, we will focus mostly on size, spacing and position. Other properties such as <code>minWidth</code> or <code>maxHeight</code> require a more complex context and we won't insist on them.</p>
<p>We're gonna chain these tweens and start the animation. You can download this example <ahref='http://codepen.io/thednp/share/zip/xwqYbX/'>here</a>.</p>
<p>TIP: the <code>width</code> and <code>height</code> properties used together can be great for <code>scale</code> animation fallback on images for legacy browsers.</p>
<h2>Text Properties</h2>
<p>OK here we're gonna do a cool example for text properties. Basically the below code would work:</p>
var tween2 = KUTE.to('selector1',{line-height:24});
var tween3 = KUTE.to('selector1',{letter-spacing:50});
</code></pre>
<p>But our example will feature some more than just that. We're gonna animate each character of a given string, with a small delay. The heading will animate <code>fontSize</code> and <code>letterSpacing</code> properties for each character while the button will animate <code>fontSize</code> and <code>lineHeight</code> properties. Watch this:</p>
<p>TIP: this should also work in IE8 as a fallback for scale animation for text. It's not perfect, can be improved for sure, but if it's a must, this would do. Download this example <ahref='http://codepen.io/thednp/share/zip/bVqLpb/'>here</a>.</p>
<h2>Color Properties</h2>
<p>The next example is about animating color properties. As for example, check these lines for reference.</p>
<p>A quick reminder: you can also use <code>RGB</code> or <code>RGBA</code>, but the last one is not supported on IE8 and it will fallback to <code>RGB</code>.</p>
<h2>Clip Property</h2>
<p>This property allows you to animate the rectangular shape of an element that is set to <code>position:absolute</code>. In CSS this property works like this <code>clip: rect(top,right,bottom,left)</code> forming a rectangular shape that masks an element making parts of it invisible.</p>
<divclass="example-item example-box bg-red"style="position: absolute; background: url('http://img.dummy-image-generator.com/people/dummy-250x250-Eye.jpg') center center no-repeat;"></div>
<divclass="example-buttons">
<aclass="btn btn-olive"href="#">Start</a>
</div>
</div>
<p><strong>Note</strong> that this would produce no effect for elements that have <code>overflow:visible</code> style rule. Download this example <ahref='http://codepen.io/thednp/pen/NGpYmM/'>here</a>.</p>
<h2>Background Position</h2>
<p>Another property we can animate with KUTE.js is <code>backgroundPosition</code>. Quick example:</p>
<divclass="example-item example-box"style="background: url('http://img.dummy-image-generator.com/abstract/dummy-400x300-Rope.jpg') center center no-repeat;"></div>
<divclass="example-buttons">
<aclass="btn btn-lime"href="#">Start</a>
</div>
</div>
<p>Download this example <ahref='http://codepen.io/thednp/share/zip/EVWEwJ/'>here</a>.</p>
<h2>Vertical Scrolling</h2>
<p>Another property we can animate with KUTE.js is <code>scrollTop</code>. I works for both the window and any scrollable object. Quick example:</p>
<pre><codeclass="language-javascript">KUTE.to('selector',{scroll:450}).start(); // for a scrollable element
KUTE.to('window',{scroll:450}).start(); // for the window
</code></pre>
<p>A working example would work like <ahref="http://codepen.io/thednp/pen/bVqKmp/"target="_blank">this</a>. Scroll works with IE8+ and is a unitless property even if these scroll distances are measured in pixels.</p>
<p>Unlike the examples <ahref="http://codepen.io/thednp/pens/public/"target="_blank">hosted on Codepen</a>, most examples here should be supported on legacy browsers. The next example is going to explain more details about how to target browsers according to their supported properties, so stick around. So, if your target audience uses legacy browsers in a significant percent, check to have the proper polyfills and also make sure you target your browsers, here's a <ahref="http://browserhacks.com/"target="_blank">complete reference</a>. Now we are ready:</li>
<p>Let's explain this code a bit. KUTE.js gives you the internal variables <code>myTween.playing</code> and <code>myTween.paused</code> (both true/false) to help you easily manage the tween control methods all together as in this example here. As said before, KUTE.js version 0.9.5 doesn't stat animating by default, for all the examples on this page you have to start it yourself, unlike their versions hosted on Codepen.</p>
<li>the <codeclass="bg-blue">START</code> button will use the <code>.start()</code> method and the animation starts;</li>
<li>the <codeclass="bg-red">STOP</code> button will use the <code>.stop()</code> method and stops the animation; after this the, animation can only be started again</li>
<li>the <codeclass="bg-orange">PAUSE</code> button will use the <code>.pause()</code> method and pauses the animation; this also changes the button's text and functionality;</li>
<li>the <codeclass="bg-olive">RESUME</code> button will use the <code>.resume()</code> method and resumes the animation; this reverses the button's initial state;</li>
<li>make sure you work with the conditions properly when you want to pause an animation you MUST check both <code>!myTween.playing</code> and <code>myTween.paused</code> conditions because you could end up with errors.</li>
</ul>
<ulid="share"class="nav">
<li>Share </li>
<liclass="hidden-xs"><atarget="_blank"href="https://www.facebook.com/sharer/sharer.php?u=http://thednp.github.io/kute.js/index.html"title="Share KUTE.js on Facebook"><spanclass="ion-social-facebook-outline icon"></span></a></li>
<liclass="hidden-xs"><atarget="_blank"href="https://twitter.com/home?status=Spread the word about @kute.js animation engine by @thednp and download here http://thednp.github.io/kute.js/index.html"title="Share KUTE.js on Twitter"><spanclass="icon ion-social-twitter-outline"></span></a></a></li>
<liclass="hidden-xs"><atarget="_blank"href="https://plus.google.com/share?url=http://thednp.github.io/kute.js/index.html"title="Share KUTE.js on Google+"><spanclass="icon ion-social-googleplus-outline"></span></a></li>
</ul>
</div>
<!-- FOOTER -->
<footer>
<divclass="content-wrap">
<pclass="pull-right"><aid="toTop"href="#">Back to top</a></p>