basic.mustache revision 3883a992e58e3629e15903ab299e20fce8483e2c
4632N/A<link href="{{componentAssets}}/anim.css" rel="stylesheet" type="text/css">
4632N/A<div class="intro">
4632N/A <p>This demonstrates how to animate the <code>opacity</code> of an element.</p>
4632N/A <p> Click the X in the header to fade out the element.</p>
4632N/A</div>
4632N/A
4632N/A<div class="example">
4632N/A{{>basic-source}}
4632N/A</div>
4632N/A
4632N/A<h2>Setting up the HTML</h2>
4632N/A<p>First we add some HTML to animate.</p>
4632N/A
4632N/A```
4632N/A{{>basic-source-html}}
4632N/A```
4632N/A
4632N/A<h2>Creating the Anim Instance</h2>
4632N/A<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 and the <code>to</code> attribute containing the final properties and their values.</p>
4632N/A
4632N/A```
4632N/Avar anim = new Y.Anim({
4632N/A node: '#demo',
4632N/A to: { opacity: 0 }
});
```
<h2>Handling the Click Event</h2>
<p>Clicking the toggle control should start the animation, so we'll need to handle that click, including preventing the default action of following the url.</p>
```
var onClick = function(e) {
e.preventDefault();
anim.run();
};
```
<h2>Running the Animation</h2>
<p>Finally we add an event listener to run the animation.</p>
```
Y.one('#demo .yui3-remove').on('click', onClick);
```
<h2>Complete Example Source</h2>
```
{{>basic-source}}
```