<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Anim</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>Anim</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><link href="../assets/anim/anim.css" rel="stylesheet" type="text/css">
<div class="intro">
<p>This demonstrates how to animate the position of an element along a <code>curve</code>.</p>
<p>Click anywhere on the gray box below and the little orange box will move to the click position.</p>
</div>
<div class="example">
<div id="demo-stage">
<span id="demo"></span>
</div>
<script type="text/javascript">
YUI().use('anim', function(Y) {
var node = Y.one('#demo');
var anim = new Y.Anim({
node: node,
duration: 1.5,
easing: Y.Easing.easeOut
});
var randomCurve = function(end) {
var points = [],
n = 3,
winWidth = node.get('winWidth'),
winHeight = node.get('winHeight');
for (var i = 0; i < n; ++i) {
points.push([
Math.floor(Math.random() * winWidth),
Math.floor(Math.random() * winHeight)
]);
}
if (end) {
points.push(end);
}
return points;
};
var onClick = function(e) {
anim.set('to', {
curve: randomCurve([e.pageX, e.pageY])
});
anim.run();
};
Y.one('#demo-stage').on('click', onClick);
});
</script>
</div>
<h2 id="setting-up-the-html">Setting up the HTML</h2>
<p>First we add some HTML to animate.</p>
<pre class="code prettyprint"><div id="demo-stage">
<span id="demo"></span>
</div></pre>
<h2 id="creating-the-anim-instance">Creating the Anim Instance</h2>
<p>Now we create an instance of <code>Y.Anim</code>, passing it a configuration object that includes the <code>node</code> we wish to animate.</p>
<pre class="code prettyprint">var node = Y.one('#demo');
var anim = new Y.Anim({
node: node,
duration: 1.5,
easing: Y.Easing.easeOut
});</pre>
<h2 id="changing-attributes">Changing Attributes</h2>
<p>A click handler will set the <code>to</code> value before <code>run</code> is called.</p>
<pre class="code prettyprint">var onClick = function(e) {
anim.set('to', {
curve: randomCurve([e.pageX, e.pageY])
});
anim.run();
};</pre>
<h2 id="running-the-animation">Running the Animation</h2>
<p>Finally we add an event handler to run the animation.</p>
<pre class="code prettyprint">Y.one('#demo-stage').on('click', onClick);</pre>
<h2 id="complete-example-source">Complete Example Source</h2>
<pre class="code prettyprint"><div id="demo-stage">
<span id="demo"></span>
</div>
<script type="text/javascript">
YUI().use('anim', function(Y) {
var anim = new Y.Anim({
node: '#demo',
duration: 0.5,
easing: Y.Easing.elasticOut
});
var onClick = function(e) {
anim.set('to', { xy: [e.pageX, e.pageY] });
anim.run();
};
Y.one('#demo-stage').on('click', onClick);
});
</script></pre>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#setting-up-the-html">Setting up the HTML</a>
</li>
<li>
<a href="#creating-the-anim-instance">Creating the Anim Instance</a>
</li>
<li>
<a href="#changing-attributes">Changing Attributes</a>
</li>
<li>
<a href="#running-the-animation">Running the Animation</a>
</li>
<li>
<a href="#complete-example-source">Complete Example Source</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Creating and using a simple animation.">
<a href="basic.html">Basic Animation</a>
</li>
<li data-description="The Animation Utility allows you to implement 'easing effects' — for example, when an animation gradually slows down as it nears completion, that's an easing effect known as 'ease-in'. This example shows you how to use easing effects with your animations.">
<a href="easing.html">Easing Effects</a>
</li>
<li data-description="Color animations can be effective indicators of state during the lifespan of a dynamic page. This example shows you how to animate color attributes of an element.">
<a href="colors.html">Animating Colors</a>
</li>
<li data-description="The direction attribute can be used to reverse the animation on alternate iterations.">
<a href="alt-iterations.html">Alternating Iterations</a>
</li>
<li data-description="This example shows you how to animate the xy coordinates of an element.">
<a href="anim-xy.html">Animating XY Position</a>
</li>
<li data-description="This example demonstrates animating an element along a curved path using bezier control points.">
<a href="curve.html">Animating Along a Curved Path</a>
</li>
<li data-description="The reverse attribute allows you to change the run direction of an animation.">
<a href="reverse.html">Reversing an Animation</a>
</li>
<li data-description="This example demonstrates how to use the end event.">
<a href="end-event.html">Using the End Event</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples That Use This Component</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Working with multiple YUI instances.">
<a href="../yui/yui-multi.html">Multiple Instances</a>
</li>
<li data-description="Shows how to create a simple plugin to animate the Overlay's movement and visibility.">
<a href="../overlay/overlay-anim-plugin.html">Animation Plugin</a>
</li>
<li data-description="How to make an animated node a Drop target.">
<a href="../dd/anim-drop.html">Animated Drop Targets</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/anim',
name: 'anim',
title: 'Anim',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('basic');
YUI.Env.Tests.examples.push('easing');
YUI.Env.Tests.examples.push('colors');
YUI.Env.Tests.examples.push('alt-iterations');
YUI.Env.Tests.examples.push('anim-xy');
YUI.Env.Tests.examples.push('curve');
YUI.Env.Tests.examples.push('reverse');
YUI.Env.Tests.examples.push('end-event');
YUI.Env.Tests.examples.push('yui-multi');
YUI.Env.Tests.examples.push('overlay-anim-plugin');
YUI.Env.Tests.examples.push('anim-drop');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>