anim-xy.mustache revision 70a56a4860f974884bce155389d59e365e18e111
<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>
```
<span id="demo"></span>
```
<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.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}}
```