~bcsaller/juju-gui/charmFind

« back to all changes in this revision

Viewing changes to lib/yui/docs/anim/reverse.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Example: Reversing an Animation</title>
6
 
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
 
    <link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
 
    <link rel="stylesheet" href="../assets/css/main.css">
9
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
 
    <script src="../../build/yui/yui-min.js"></script>
11
 
</head>
12
 
<body>
13
 
 
14
 
<div id="doc">
15
 
    <h1>Example: Reversing an Animation</h1>
16
 
 
17
 
    
18
 
 
19
 
    <div class="yui3-g">
20
 
        <div class="yui3-u-3-4">
21
 
            <div id="main">
22
 
                <div class="content"><link href="../assets/anim/anim.css" rel="stylesheet" type="text/css">
23
 
<div class="intro">
24
 
    <p>This demonstrates how to use the <code>reverse</code> attribute to change the behavior of the animation.</p>
25
 
    <p> Click the icon in the header to toggle the element's <code>height</code>.</p>
26
 
</div>
27
 
 
28
 
<div class="example">
29
 
<div id="demo" class="yui3-module">
30
 
    <div class="yui3-hd">
31
 
        <h3>Reversing an Animation</h3>
32
 
    </div>
33
 
    <div class="yui3-bd">
34
 
        <p>Click the icon in the header to toggle the element's height.</p>
35
 
    </div>
36
 
</div>
37
 
<p>This is placeholder text used to demonstrate how the above animation affects subsequent content.</p> 
38
 
 
39
 
 
40
 
<script type="text/javascript">
41
 
YUI().use('anim', function(Y) {
42
 
    var module = Y.one('#demo');
43
 
 
44
 
    // add fx plugin to module body
45
 
    var content = module.one('.yui3-bd').plug(Y.Plugin.NodeFX, {
46
 
        from: { height: 1 },
47
 
        to: {
48
 
            height: function(node) { // dynamic in case of change
49
 
                return node.get('scrollHeight'); // get expanded height (offsetHeight may be zero)
50
 
            }
51
 
        },
52
 
 
53
 
        easing: Y.Easing.easeOut,
54
 
        duration: 0.5
55
 
    });
56
 
 
57
 
    var onClick = function(e) {
58
 
        module.toggleClass('yui3-closed');
59
 
        content.fx.set('reverse', !content.fx.get('reverse')); // toggle reverse 
60
 
        content.fx.run();
61
 
    };
62
 
 
63
 
    // use dynamic control for dynamic behavior
64
 
    var control = Y.Node.create(
65
 
        '<a title="collapse/expand element" class="yui3-toggle">' +
66
 
            '<em>toggle</em>' +
67
 
        '</a>'
68
 
    );
69
 
 
70
 
    // append dynamic control to header section
71
 
    module.one('.yui3-hd').appendChild(control);
72
 
    control.on('click', onClick);
73
 
 
74
 
});
75
 
</script>
76
 
 
77
 
</div>
78
 
 
79
 
<h2>Setting up the HTML</h2>
80
 
<p>First we add some HTML to animate.</p>
81
 
 
82
 
<pre class="code prettyprint">&lt;div id=&quot;demo&quot; class=&quot;yui3-module&quot;&gt;
83
 
    &lt;div class=&quot;yui3-hd&quot;&gt;
84
 
        &lt;h3&gt;Reversing an Animation&lt;&#x2F;h3&gt;
85
 
    &lt;&#x2F;div&gt;
86
 
    &lt;div class=&quot;yui3-bd&quot;&gt;
87
 
        &lt;p&gt;Click the icon in the header to toggle the element&#x27;s height.&lt;&#x2F;p&gt;
88
 
    &lt;&#x2F;div&gt;
89
 
&lt;&#x2F;div&gt;
90
 
&lt;p&gt;This is placeholder text used to demonstrate how the above animation affects subsequent content.&lt;&#x2F;p&gt;</pre>
91
 
 
92
 
 
93
 
<h2>Using the NodeFX Plugin</h2>
94
 
<p>For this example, we will use <code>Node</code>'s <code>fx</code> plugin to animate the element.  The plugin adds the anim instance to the <code>Node</code> instance, pre-configuring it to use the Node instance as the <code>Anim</code>'s node.  The <code>plug</code> method accepts a class to construct and an optional config to pass to the constructor.</p>
95
 
<p>Setting the <code>from</code> attribute to the expanded height of the element allows us to toggle the effect using the <code>reverse</code> attribute, which we will see below (<code>from</code> uses current value when omitted).</p>
96
 
 
97
 
<pre class="code prettyprint">var module = Y.one(&#x27;#demo&#x27;);
98
 
 
99
 
&#x2F;&#x2F; add fx plugin to module body
100
 
var content = module.one(&#x27;.yui3-bd&#x27;).plug(Y.Plugin.NodeFX, {
101
 
    from: { height: 0 },
102
 
    to: {
103
 
        height: function(node) { &#x2F;&#x2F; dynamic in case of change
104
 
            return node.get(&#x27;scrollHeight&#x27;); &#x2F;&#x2F; get expanded height (offsetHeight may be zero)
105
 
        }
106
 
    },
107
 
 
108
 
    easing: Y.Easing.easeOut,
109
 
    from: { height: 0 },
110
 
    duration: 0.5
111
 
});</pre>
112
 
 
113
 
 
114
 
<h2>Creating the Control Element</h2>
115
 
<p>Because our behavior only works when JS is available, let's go ahead and add our control element using JS as well.</p>
116
 
 
117
 
<pre class="code prettyprint">&#x2F;&#x2F; use dynamic control for dynamic behavior
118
 
var control = Y.Node.create(
119
 
    &#x27;&lt;a title=&quot;show&#x2F;hide content&quot; class=&quot;yui3-toggle&quot;&gt;&#x27; +
120
 
        &#x27;&lt;em&gt;toggle&lt;&#x2F;em&gt;&#x27; +
121
 
    &#x27;&lt;&#x2F;a&gt;&#x27;
122
 
);
123
 
 
124
 
&#x2F;&#x2F; append dynamic control to header section
125
 
module.one(&#x27;.yui3-hd&#x27;).appendChild(control);</pre>
126
 
 
127
 
 
128
 
<h2>Toggling Animation Behavior</h2>
129
 
<p>Before calling <code>run</code> in our <code>click</code> handler, we will use the <code>reverse</code> attribute toggle the direction of the animation depending on whether its opening or closing.</p>
130
 
 
131
 
<pre class="code prettyprint">var onClick = function(e) {
132
 
    module.toggleClass(&#x27;yui-closed&#x27;);
133
 
    content.fx.set(&#x27;reverse&#x27;, !content.fx.get(&#x27;reverse&#x27;)); &#x2F;&#x2F; toggle reverse
134
 
};</pre>
135
 
 
136
 
 
137
 
<h2>Running the Animation</h2>
138
 
<p>Finally we add an event handler to run the animation.</p>
139
 
 
140
 
<pre class="code prettyprint">module.one(&#x27;.yui3-toggle&#x27;).on(&#x27;click&#x27;, onClick);</pre>
141
 
 
142
 
 
143
 
<h2>Complete Example Source</h2>
144
 
<pre class="code prettyprint">&lt;div id=&quot;demo&quot; class=&quot;yui3-module&quot;&gt;
145
 
    &lt;div class=&quot;yui3-hd&quot;&gt;
146
 
        &lt;h3&gt;Reversing an Animation&lt;&#x2F;h3&gt;
147
 
    &lt;&#x2F;div&gt;
148
 
    &lt;div class=&quot;yui3-bd&quot;&gt;
149
 
        &lt;p&gt;Click the icon in the header to toggle the element&#x27;s height.&lt;&#x2F;p&gt;
150
 
    &lt;&#x2F;div&gt;
151
 
&lt;&#x2F;div&gt;
152
 
&lt;p&gt;This is placeholder text used to demonstrate how the above animation affects subsequent content.&lt;&#x2F;p&gt; 
153
 
 
154
 
 
155
 
&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
156
 
YUI().use(&#x27;anim&#x27;, function(Y) {
157
 
    var module = Y.one(&#x27;#demo&#x27;);
158
 
 
159
 
    &#x2F;&#x2F; add fx plugin to module body
160
 
    var content = module.one(&#x27;.yui3-bd&#x27;).plug(Y.Plugin.NodeFX, {
161
 
        from: { height: 1 },
162
 
        to: {
163
 
            height: function(node) { &#x2F;&#x2F; dynamic in case of change
164
 
                return node.get(&#x27;scrollHeight&#x27;); &#x2F;&#x2F; get expanded height (offsetHeight may be zero)
165
 
            }
166
 
        },
167
 
 
168
 
        easing: Y.Easing.easeOut,
169
 
        duration: 0.5
170
 
    });
171
 
 
172
 
    var onClick = function(e) {
173
 
        module.toggleClass(&#x27;yui3-closed&#x27;);
174
 
        content.fx.set(&#x27;reverse&#x27;, !content.fx.get(&#x27;reverse&#x27;)); &#x2F;&#x2F; toggle reverse 
175
 
        content.fx.run();
176
 
    };
177
 
 
178
 
    &#x2F;&#x2F; use dynamic control for dynamic behavior
179
 
    var control = Y.Node.create(
180
 
        &#x27;&lt;a title=&quot;collapse&#x2F;expand element&quot; class=&quot;yui3-toggle&quot;&gt;&#x27; +
181
 
            &#x27;&lt;em&gt;toggle&lt;&#x2F;em&gt;&#x27; +
182
 
        &#x27;&lt;&#x2F;a&gt;&#x27;
183
 
    );
184
 
 
185
 
    &#x2F;&#x2F; append dynamic control to header section
186
 
    module.one(&#x27;.yui3-hd&#x27;).appendChild(control);
187
 
    control.on(&#x27;click&#x27;, onClick);
188
 
 
189
 
});
190
 
&lt;&#x2F;script&gt;</pre>
191
 
 
192
 
</div>
193
 
            </div>
194
 
        </div>
195
 
 
196
 
        <div class="yui3-u-1-4">
197
 
            <div class="sidebar">
198
 
                
199
 
 
200
 
                
201
 
                    <div class="sidebox">
202
 
                        <div class="hd">
203
 
                            <h2 class="no-toc">Examples</h2>
204
 
                        </div>
205
 
 
206
 
                        <div class="bd">
207
 
                            <ul class="examples">
208
 
                                
209
 
                                    
210
 
                                        <li data-description="Creating and using a simple animation.">
211
 
                                            <a href="basic.html">Basic Animation</a>
212
 
                                        </li>
213
 
                                    
214
 
                                
215
 
                                    
216
 
                                        <li data-description="The Animation Utility allows you to implement &#x27;easing effects&#x27; &mdash; for example, when an animation gradually slows down as it nears completion, that&#x27;s an easing effect known as &#x27;ease-in&#x27;.  This example shows you how to use easing effects with your animations.">
217
 
                                            <a href="easing.html">Easing Effects</a>
218
 
                                        </li>
219
 
                                    
220
 
                                
221
 
                                    
222
 
                                        <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.">
223
 
                                            <a href="colors.html">Animating Colors</a>
224
 
                                        </li>
225
 
                                    
226
 
                                
227
 
                                    
228
 
                                        <li data-description="The direction attribute can be used to reverse the animation on alternate iterations.">
229
 
                                            <a href="alt-iterations.html">Alternating Iterations</a>
230
 
                                        </li>
231
 
                                    
232
 
                                
233
 
                                    
234
 
                                        <li data-description="This example shows you how to animate the xy coordinates of an element.">
235
 
                                            <a href="anim-xy.html">Animating XY Position</a>
236
 
                                        </li>
237
 
                                    
238
 
                                
239
 
                                    
240
 
                                        <li data-description="This example demonstrates animating an element along a curved path using bezier control points.">
241
 
                                            <a href="curve.html">Animating Along a Curved Path</a>
242
 
                                        </li>
243
 
                                    
244
 
                                
245
 
                                    
246
 
                                        <li data-description="The reverse attribute allows you to change the run direction of an animation.">
247
 
                                            <a href="reverse.html">Reversing an Animation</a>
248
 
                                        </li>
249
 
                                    
250
 
                                
251
 
                                    
252
 
                                        <li data-description="This example demonstrates how to use the end event.">
253
 
                                            <a href="end-event.html">Using the End Event</a>
254
 
                                        </li>
255
 
                                    
256
 
                                
257
 
                                    
258
 
                                
259
 
                                    
260
 
                                
261
 
                                    
262
 
                                
263
 
                            </ul>
264
 
                        </div>
265
 
                    </div>
266
 
                
267
 
 
268
 
                
269
 
                    <div class="sidebox">
270
 
                        <div class="hd">
271
 
                            <h2 class="no-toc">Examples That Use This Component</h2>
272
 
                        </div>
273
 
 
274
 
                        <div class="bd">
275
 
                            <ul class="examples">
276
 
                                
277
 
                                    
278
 
                                
279
 
                                    
280
 
                                
281
 
                                    
282
 
                                
283
 
                                    
284
 
                                
285
 
                                    
286
 
                                
287
 
                                    
288
 
                                
289
 
                                    
290
 
                                
291
 
                                    
292
 
                                
293
 
                                    
294
 
                                        <li data-description="Shows how to create a simple plugin to animate the Overlay&#x27;s movement and visibility.">
295
 
                                            <a href="../overlay/overlay-anim-plugin.html">Animation Plugin</a>
296
 
                                        </li>
297
 
                                    
298
 
                                
299
 
                                    
300
 
                                        <li data-description="Working with multiple YUI instances.">
301
 
                                            <a href="../yui/yui-multi.html">Multiple Instances</a>
302
 
                                        </li>
303
 
                                    
304
 
                                
305
 
                                    
306
 
                                        <li data-description="How to make an animated node a Drop target.">
307
 
                                            <a href="../dd/anim-drop.html">Animated Drop Targets</a>
308
 
                                        </li>
309
 
                                    
310
 
                                
311
 
                            </ul>
312
 
                        </div>
313
 
                    </div>
314
 
                
315
 
            </div>
316
 
        </div>
317
 
    </div>
318
 
</div>
319
 
 
320
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
321
 
<script>prettyPrint();</script>
322
 
 
323
 
</body>
324
 
</html>