anim-xy.mustache revision 1f08a8488664773a7d96fa3a043a639692d2a5cb
<link href="{{componentAssets}}/anim.css" rel="stylesheet" type="text/css">
<div class="intro">
<p>This demonstrates how to animate the <code>xy</code> position of an element.</p>
<p> Click anywhere to move the element to your click position.</p>
</div>
<div class="example">
{{>anim-xy-source}}
</div>
<h3>Setting up the HTML</h3>
<p>First we add some HTML to animate.</p>
```
<div id="demo" class="yui3-module">
<div class="yui3-hd">
<h4>Animation Demo</h4>
<a title="remove module" class="yui3-remove"><em>x</em></a>
</div>
<div class="yui3-bd">
<p>This an example of what you can do with the YUI Animation Utility.</p>
<p><em>Follow the instructions above to see the animation in action.</em></p>
</div>
</div>
```
<h3>Creating the Anim Instance</h3>
<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. We will set the <code>to</code> attribute later when then animation runs.</p>
```
var anim = new Y.Anim({
node: '#demo',
duration: 0.5,
easing: Y.Easing.elasticOut
});
```
<h3>Changing Attributes</h3>
<p>Next we need a <code>click</code> handler to set the <code>to</code> attribute for the <code>xy</code> behavior and run the animation.</p>
```
var onClick = function(e) {
anim.set('to', { xy: [e.pageX, e.pageY] });
anim.run();
};
```
<h3>Running the Animation</h3>
<p>Finally we add an event handler to run the animation when the document is clicked.</p>
```
Y.one('document').on('click', onClick);
```
<h2>Complete Example Source</h2>
```
{{>anim-xy-source}}
```