diff --git a/src/anim/docs/alt-iterations.mustache b/src/anim/docs/alt-iterations.mustache new file mode 100644 index 00000000000..a191d78628e --- /dev/null +++ b/src/anim/docs/alt-iterations.mustache @@ -0,0 +1,82 @@ + +
+

This demonstrates how to use the iterations attribute to run multiple iterations of the animation.

+

Mouse over the link to begin the animation.

+
+ +
+{{>alt-iterations-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +hover me +``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate and the to attribute containing the final properties and their values.

+

Adding an iterations attribute of "infinite" means that the animation will run continuously.

+

The direction attribute of "alternate" means that the animation reverses every other iteration.

+ +``` +var node = Y.one('#demo'); + +var anim = new Y.Anim({ + node: node, + from: { + backgroundColor:node.getStyle('backgroundColor'), + color: node.getStyle('color'), + borderColor: node.getStyle('borderTopColor') + }, + + to: { + color: '#fff', + backgroundColor:'#ffa928', + borderColor: '#71241a' + }, + + duration: 0.5, + iterations: 'infinite', + direction: 'alternate' +}); +``` + +

Changing Attributes

+

We don't want the animation running when the link is not hovered over, so we will change the animation attributes depending on whether or not we are over the link.

+

We can use a single handler for both mouse the mouseOver and mouseOut events, and set the reverse attribute depending on which event fired.

+ +``` +var hover = function(e) { + var reverse = false, + iterations = 'infinite'; + + if (anim.get('running')) { + anim.pause(); + } + if (e.type === 'mouseout') { + reverse = true; + iterations = 1; + } + anim.setAttrs({ + 'reverse': reverse, + 'iterations': iterations + }); + + anim.run(); +}; +``` + +

Running the Animation

+

Finally we add event handlers to run the animation.

+ +``` +node.on('mouseover', hover); +node.on('mouseout', hover); +``` + +

Complete Example Source

+``` +{{>alt-iterations-source}} +``` diff --git a/src/anim/docs/anim-xy.mustache b/src/anim/docs/anim-xy.mustache new file mode 100644 index 00000000000..4bdcca4dc9f --- /dev/null +++ b/src/anim/docs/anim-xy.mustache @@ -0,0 +1,58 @@ + +
+

This demonstrates how to animate the xy position of an element.

+

Click anywhere to move the element to your click position.

+
+ +
+{{>anim-xy-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +
+
+

Animation Demo

+ x +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate. We will set the to attribute later when then animation runs.

+ +``` +var anim = new Y.Anim({ + node: '#demo', + duration: 0.5, + easing: Y.Easing.elasticOut +}); +``` + +

Changing Attributes

+

Next we need a click handler to set the to attribute for the xy behavior and run the animation.

+ +``` +var onClick = function(e) { + anim.set('to', { xy: [e.pageX, e.pageY] }); + anim.run(); +}; +``` + +

Running the Animation

+

Finally we add an event handler to run the animation when the document is clicked.

+ +``` +Y.one('document').on('click', onClick); +``` + +

Complete Example Source

+``` +{{>anim-xy-source}} +``` diff --git a/src/anim/docs/assets/anim.css b/src/anim/docs/assets/anim.css new file mode 100644 index 00000000000..12aaf3f2c6c --- /dev/null +++ b/src/anim/docs/assets/anim.css @@ -0,0 +1,142 @@ +/* color and iteration examples */ +a#demo { + background:#8dd5e7; + border:1px solid #004c6d; + color:#004c6d; + display:block; + height:2em; + line-height:2em; + width:6em; + text-align:center; +} + +/* xy and curve examples */ +span#demo { + background:#ffa928; + display:block; + height:10px; + width:10px; +} + +/* module examples */ +div#demo { + width:22em; + overflow:hidden; +} + +div#demo { + border-bottom:1px solid #7a97bb; +} + +div#demo .yui3-hd { + background: #406ed9; + border:1px solid #243356; + zoom:1; +} + +div#demo .yui3-hd h3 { + border:0; + color:#fff; + margin:0; +} + +#demo .yui3-hd a { /* module control (close remove, etc) */ + background:url(sprite.png) no-repeat; + color:#abceff; + cursor:pointer; + cursor:hand; + display: inline; /* prevent IE margin doubling */ + float: right; + margin-top: -18px; + height:12px; + width:24px; + overflow:hidden; + text-align: right; + text-decoration:none; + text-indent:9999px; +} + +div#demo .yui3-bd { + background:#abceff; + border:solid #7a97bb; + border-width:0 1px; + clear: both; + overflow:hidden; + zoom:1; +} + +div#demo .yui3-hd, +div#demo .yui3-bd p { + margin:0; + padding:0.5em 1em; +} + +div#demo div.yui3-bd p { + margin:0.3em 10px 0 0; /* right margin for scrollbar space */ +} + +div#demo .yui3-bd p em { + font-weight:bold; +} + +/* basic example */ +div#demo a.yui3-remove { + background-position:0 -300px; + height:16px; + width:26px; +} + +/* scroll example */ +#demo.yui3-scroll { + position: relative; +} + +.yui3-scroll .yui3-hd { + position: relative; +} +.yui3-scroll .yui3-bd { + height:10em; + overflow:hidden; +} + +#demo .yui3-hd .yui3-scroll-controls { /* fake scrollbar */ + background:#dfdfdf; + border-left:1px solid #7a97bb; + height:10em; + width:13px; + position:absolute; + right:0; + bottom:-10.1em; + overflow:hidden; +} + +#demo .yui3-hd .yui3-scroll-controls a { + margin: 0; + position:absolute; + top:0; + right:0; + height:14px; + width:14px; + Xborder:1px solid #000; +} + +#demo .yui3-scroll-controls a.yui3-scrollup { + background-position:-12px -752px; /* scroll up icon */ +} + +#demo .yui3-scroll-controls a.yui3-scrolldown { + background-position:-12px -804px; /* scroll down icon */ + top:auto; + bottom:0; +} + +/* reverse and easing examples */ +#demo a.yui3-toggle { + background-position:0 -400px; /* close (minus) icon */ + height:15px; + width:15px; +} + +#demo.yui3-closed a.yui3-toggle { + background-position:0 -350px; /* open (plus) icon */ +} diff --git a/src/anim/docs/assets/sprite.png b/src/anim/docs/assets/sprite.png new file mode 100644 index 00000000000..afd65e05aaa Binary files /dev/null and b/src/anim/docs/assets/sprite.png differ diff --git a/src/anim/docs/basic.mustache b/src/anim/docs/basic.mustache new file mode 100644 index 00000000000..d8775f3c4c2 --- /dev/null +++ b/src/anim/docs/basic.mustache @@ -0,0 +1,56 @@ + +
+

This demonstrates how to animate the opacity of an element.

+

Click the X in the header to fade the element out.

+
+ +
+{{>basic-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +
+
+

Animation Demo

+ x +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate and the to attribute containing the final properties and their values.

+ +``` +var anim = new Y.Anim({ + node: '#demo', + to: { opacity: 0 } +}); +``` + +

Handling the Click Event

+

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.

+ +``` +var onClick = function(e) { + e.preventDefault(); + anim.run(); +}; +``` + +

Running the Animation

+

Finally we add an event listener to run the animation.

+``` +Y.one('#demo .yui3-remove').on('click', onClick); +``` + +

Complete Example Source

+``` +{{>basic-source}} +``` diff --git a/src/anim/docs/colors.mustache b/src/anim/docs/colors.mustache new file mode 100644 index 00000000000..7c0769cd0dc --- /dev/null +++ b/src/anim/docs/colors.mustache @@ -0,0 +1,69 @@ + +
+

This demonstrates how to animate color attributes.

+

Mouse over the link to begin the animation.

+
+ +
+{{>colors-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +hover me +``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate and the to attribute containing the final properties and their values.

+

Adding a from attribute allows us to reset the colors onmouseout using the reverse attribute, which we will see below.

+ +``` +var node = Y.one('#demo'); + +var anim = new Y.Anim({ + node: node, + from: { + backgroundColor:node.getStyle('backgroundColor'), + color: node.getStyle('color'), + borderColor: node.getStyle('borderTopColor') + }, + + to: { + color: '#fff', + backgroundColor:'#ffa928', + borderColor: '#71241a' + }, + + duration:0.5 +}); +``` + +

Running the Animation

+

Next we need a handler to run when the link is moused over, and reverse when moused out.

+``` +var hover = function(e) { + var reverse = false; + if (anim.get('running')) { + anim.pause(); + } + if (e.type === 'mouseout') { + reverse = true; + } + anim.set('reverse', reverse); + anim.run(); +}; +``` + +

Listening for the Events

+

Finally we add an event handler to run the animation.

+``` +node.on('mouseover', hover); +node.on('mouseout', hover); +``` + +

Complete Example Source

+``` +{{>colors-source}} +``` diff --git a/src/anim/docs/component.json b/src/anim/docs/component.json new file mode 100644 index 00000000000..6aa55e696e2 --- /dev/null +++ b/src/anim/docs/component.json @@ -0,0 +1,102 @@ +{ + "name" : "anim", + "displayName": "Anim", + "description": "The Animation Utility allows properties to animate the transition between values.", + "author" : "msweeney", + + "tags": ["utility", "anim"], + "use" : ["anim"], + + "examples": [ + { + "name" : "basic", + "displayName": "Basic Animation", + "description": "Creating and using a simple animation.", + "modules" : ["anim"], + "tags" : ["anim"], + + "hideTableOfContents": true + }, + + { + "name" : "easing", + "displayName": "Easing Effects", + "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.", + "modules" : ["anim"], + "tags" : ["anim", "easing"], + + "hideTableOfContents": true + }, + + { + "name" : "colors", + "displayName": "Animating Colors", + "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.", + "modules" : ["anim"], + "tags" : ["anim", "color"], + + "hideTableOfContents": true + }, + + { + "name" : "alt-iterations", + "displayName": "Alternating Iterations", + "description": "The direction attribute can be used to reverse the animation on alternate iterations.", + "modules" : ["anim"], + "tags" : ["anim", "reverse", "iterations", "direction"], + + "hideTableOfContents": true + }, + + { + "name" : "anim-xy", + "displayName": "Animating XY Position", + "description": "This example shows you how to animate the xy coordinates of an element.", + "modules" : ["anim"], + "tags" : ["anim", "xy", "position"], + + "hideTableOfContents": true + }, + + { + "name" : "curve", + "displayName": "Animating Along a Curved Path", + "description": "This example demonstrates animating an element along a curved path using bezier control points.", + "modules" : ["anim"], + "tags" : ["anim", "xy", "position", "bezier"], + + "hideTableOfContents": true + }, + + { + "name" : "reverse", + "displayName": "Reversing an Animation", + "description": "The reverse attribute allows you to change the run direction of an animation.", + "modules" : ["anim"], + "tags" : ["anim", "reverse", "plugin"], + + "hideTableOfContents": true + }, + + { + "name" : "end-event", + "displayName": "Using the End Event", + "description": "This example demonstrates how to use the end event.", + "modules" : ["anim"], + "tags" : ["anim", "event", "end"], + + "hideTableOfContents": true + }, + + { + "name" : "anim-chaining", + "displayName": "Chaining Animations Using the end Event", + "description": "Animations can be set to run sequentially using Animation's end event.", + "modules" : ["anim"], + "tags" : ["anim", "event", "end", "chain"], + + "hideTableOfContents": true + } + + ] +} diff --git a/src/anim/docs/curve.mustache b/src/anim/docs/curve.mustache new file mode 100644 index 00000000000..80715506308 --- /dev/null +++ b/src/anim/docs/curve.mustache @@ -0,0 +1,52 @@ + +
+

This demonstrates how to animate the position of an element along a curve.

+

Click anywhere to move the element to your click position.

+
+ +
+{{>curve-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+``` + +``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate.

+ +``` +var node = Y.one('#demo'); + +var anim = new Y.Anim({ + node: node, + duration: 1.5, + easing: Y.Easing.easeOut +}); +``` + +

Changing Attributes

+

A click handler will set the to value before run is called.

+ +``` +var onClick = function(e) { + anim.set('to', { + curve: randomCurve([e.pageX, e.pageY]) + }); + anim.run(); +}; +``` + +

Running the Animation

+

Finally we add an event handler to run the animation.

+ +``` +Y.one('document').on('click', onClick); +``` + +

Complete Example Source

+``` +{{>anim-xy-source}} +``` diff --git a/src/anim/docs/easing.mustache b/src/anim/docs/easing.mustache new file mode 100644 index 00000000000..0c84ed89c05 --- /dev/null +++ b/src/anim/docs/easing.mustache @@ -0,0 +1,51 @@ + +
+

This demonstrates how to use the easing attribute to change the behavior of the animation.

+

Click the icon in the header to shrink the element's height to zero with the "backIn" effect.

+
+ +
+{{>easing-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +
+
+

Animation Demo

+ - +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate and the to attribute containing the final properties and their values.

+ +``` +var anim = new Y.Anim({ + node: '#demo .yui3-bd', + to: { height: 0 }, + easing: 'backIn' +}); +``` + +

Running the Animation

+

Finally we add an event handler to run the animation.

+``` +var onClick = function(e) { + e.preventDefault(); + anim.run(); +}; +Y.one('#demo .yui3-toggle').on('click', onClick); +``` + +

Complete Example Source

+``` +{{>easing-source}} +``` diff --git a/src/anim/docs/end-event.mustache b/src/anim/docs/end-event.mustache new file mode 100644 index 00000000000..9d230006537 --- /dev/null +++ b/src/anim/docs/end-event.mustache @@ -0,0 +1,63 @@ + +
+

This demonstrates how to use the end event.

+

Click the X in the header to fade the element out and remove it from the document once the fade completes.

+
+ +
+{{>end-event-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +
+
+

Animation Demo

+ x +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+``` + +

Creating the Anim Instance

+

Now we create an instance of Y.Anim, passing it a configuration object that includes the node we wish to animate and the to attribute containing the properties to be transitioned and final values.

+ +``` +var anim = new Y.Anim({ + node: '#demo', + to: { opacity: 0 } +}); +``` + +

Handling the End Event

+

We will need a function to run when the end event fires. Note that the context of our handler defaults to anim, so this refers to our Anim instance inside the handler.

+ +``` +var onEnd = function() { + var node = this.get('node'); // this === anim + node.get('parentNode').removeChild(node); // node is an instance of Node +}; +``` + +

Listening for the End Event

+

Now we will use the on method to subscribe to the end event, passing it our handler.

+ +``` +anim.on('end', onEnd); +``` + +

Running the Animation

+

Finally we add an event handler to run the animation.

+``` +Y.one('#demo .yui3-remove').on('click', anim.run, anim); +``` + +

Complete Example Source

+``` +{{>end-event-source}} +``` diff --git a/src/anim/docs/index.mustache b/src/anim/docs/index.mustache new file mode 100644 index 00000000000..dd97dea6d0a --- /dev/null +++ b/src/anim/docs/index.mustache @@ -0,0 +1,105 @@ +
+

The Anim Utility provides the ability to animate changes to style properties. Advanced easing equations are provided for more interesting animated effects.

+
+{{>getting-started}} +
+

Creating an Animation Object

+ +

Your Animation implementation will consist of one or more instances of the Anim.

+

To create an Anim instance on your page, pass it a configuration object including the node or selector query for the node that you wish to animate and a to containing the properties you wish to animate.

+ +``` +var myAnim = new Y.Anim({ + node: '#demo', + to: { + width: 0, + height: 0 + } +}); +``` + +

To begin the actual animation, call the run method on your Anim instance.

+ +``` +myAnim.run(); +``` + +

See the API documentation for the Anim object for more information about its methods and properties.

+ +

Using Animation

+ +

Accessing Animation Attributes

+ +

In addition to passing a configuration object to the Anim constructor, you can access the attributes of your Anim instance via the set and get methods.

+ +``` +var myAnim = new Y.Anim({ + node: '#demo', + to: { + width: 0, + height: 0 + } +}); +``` + +

Setting a To Value

+

A node attribute and a to attribute containing one or more properties to animate are the minimum requirements for running an animation.

+ +

The value of a to can optionally be a function. If a function is used, it receives the node as its only argument. The return value of the function becomes the to value for that run of the animation.

+ +``` +var myAnim = new Y.Anim({ + node: '#demo', + to: { + width: function(node) { + return node.get('offsetWidth') / 2; + }, + height: 0 + } +}); +``` + +

Setting a From Value

+ +

Use the optional from attribute to start the animation from a specific value. When from is omitted, the current value is used.

+ +

Like the to attribute, the value of a from property can optionally be a function. If a function is used, it receives the node as its only argument. The return value of the function becomes the from value for that run of the animation.

+ +``` +var myAnim = new Y.Anim({ + node: '#demo', + from: { + width: 0, + height: function(node) { + return node.get('winHeight'); + } + }, + + to: { + width: 0, + height: 0 + } +}); +``` + +

Listening for Events

+ +

The Animation Utility defines events useful for hooking into the various stages of an animation. The on method is used to attach event listeners.

+``` +var myAnim = new Y.Anim({ + node: '#demo', + to: { + width: 0, + height: 0 + } +}); + +myAnim.on('end', function() { + myAnim.get('node').addClass('yui-hidden'); +}); +``` +
+ + + + diff --git a/src/anim/docs/partials/alt-iterations-source.mustache b/src/anim/docs/partials/alt-iterations-source.mustache new file mode 100644 index 00000000000..25f762714b9 --- /dev/null +++ b/src/anim/docs/partials/alt-iterations-source.mustache @@ -0,0 +1,51 @@ +hover me + + diff --git a/src/anim/docs/partials/anim-chaining-source.mustache b/src/anim/docs/partials/anim-chaining-source.mustache new file mode 100644 index 00000000000..4a336d2dd52 --- /dev/null +++ b/src/anim/docs/partials/anim-chaining-source.mustache @@ -0,0 +1,34 @@ + +
+
+

Animation Demo

+ x +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+

This is placeholder text used to demonstrate how the above animation affects subsequent content.

+ + diff --git a/src/anim/docs/partials/anim-xy-source.mustache b/src/anim/docs/partials/anim-xy-source.mustache new file mode 100644 index 00000000000..9c3d3b2febd --- /dev/null +++ b/src/anim/docs/partials/anim-xy-source.mustache @@ -0,0 +1,20 @@ + + + diff --git a/src/anim/docs/partials/basic-source.mustache b/src/anim/docs/partials/basic-source.mustache new file mode 100644 index 00000000000..35876a2d643 --- /dev/null +++ b/src/anim/docs/partials/basic-source.mustache @@ -0,0 +1,29 @@ +
+
+

Animation Demo

+ remove +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+ + + diff --git a/src/anim/docs/partials/colors-source.mustache b/src/anim/docs/partials/colors-source.mustache new file mode 100644 index 00000000000..c534c43b5d9 --- /dev/null +++ b/src/anim/docs/partials/colors-source.mustache @@ -0,0 +1,40 @@ +hover me + + diff --git a/src/anim/docs/partials/curve-source.mustache b/src/anim/docs/partials/curve-source.mustache new file mode 100644 index 00000000000..4d8dd413034 --- /dev/null +++ b/src/anim/docs/partials/curve-source.mustache @@ -0,0 +1,42 @@ + + + diff --git a/src/anim/docs/partials/easing-source.mustache b/src/anim/docs/partials/easing-source.mustache new file mode 100644 index 00000000000..df473579739 --- /dev/null +++ b/src/anim/docs/partials/easing-source.mustache @@ -0,0 +1,29 @@ + +
+
+

Animation Demo

+ toggle +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+

This is placeholder text used to demonstrate how the above animation affects subsequent content.

+ diff --git a/src/anim/docs/partials/end-event-source.mustache b/src/anim/docs/partials/end-event-source.mustache new file mode 100644 index 00000000000..0bc9152d5cf --- /dev/null +++ b/src/anim/docs/partials/end-event-source.mustache @@ -0,0 +1,30 @@ +
+
+

Animation Demo

+ x +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+

This is placeholder text used to demonstrate how the above animation affects subsequent content.

+ + diff --git a/src/anim/docs/partials/reverse-source.mustache b/src/anim/docs/partials/reverse-source.mustache new file mode 100644 index 00000000000..26bd32dc8d6 --- /dev/null +++ b/src/anim/docs/partials/reverse-source.mustache @@ -0,0 +1,47 @@ +
+
+

Animation Demo

+
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+

This is placeholder text used to demonstrate how the above animation affects subsequent content.

+ + diff --git a/src/anim/docs/reverse.mustache b/src/anim/docs/reverse.mustache new file mode 100644 index 00000000000..fd6c0171885 --- /dev/null +++ b/src/anim/docs/reverse.mustache @@ -0,0 +1,84 @@ + +
+

This demonstrates how to use the reverse attribute to change the behavior of the animation.

+

Click the icon in the header to toggle the element's height.

+
+ +
+{{>reverse-source}} +
+ +

Setting up the HTML

+

First we add some HTML to animate.

+ +``` +
+
+

Animation Demo

+ - +
+
+

This an example of what you can do with the YUI Animation Utility.

+

Follow the instructions above to see the animation in action.

+
+
+``` + +

Using the NodeFX Plugin

+

For this example, we will use Node's fx plugin to animate the element. The plugin adds the anim instance to the Node instance, pre-configuring it to use the Node instance as the Anim's node. The plug method accepts a class to construct and an optional config to pass to the constructor.

+

Setting the from attribute to the expanded height of the element allows us to toggle the effect using the reverse attribute, which we will see below (from uses current value when omitted).

+ +``` +var module = Y.one('#demo'); + +// add fx plugin to module body +var content = module.one('.yui3-bd').plug(Y.Plugin.NodeFX, { + from: { height: 0 }, + to: { + height: function(node) { // dynamic in case of change + return node.get('scrollHeight'); // get expanded height (offsetHeight may be zero) + } + }, + + easing: Y.Easing.easeOut, + from: { height: 0 }, + duration: 0.5 +}); +``` + +

Creating the Control Element

+

Because our behavior only works when JS is available, let's go ahead and add our control element using JS as well.

+ +``` +// use dynamic control for dynamic behavior +var control = Y.Node.create( + '' + + 'toggle' + + '' +); + +// append dynamic control to header section +module.one('.yui3-hd').appendChild(control); +``` + +

Toggling Animation Behavior

+

Before calling run in our click handler, we will use the reverse attribute toggle the direction of the animation depending on whether its opening or closing.

+ +``` +var onClick = function(e) { + module.toggleClass('yui-closed'); + content.fx.set('reverse', !content.fx.get('reverse')); // toggle reverse +}; +``` + +

Running the Animation

+

Finally we add an event handler to run the animation.

+ +``` +module.one('.yui3-toggle').on('click', onClick); +``` + +

Complete Example Source

+``` +{{>reverse-source}} +```