4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-Animate'>/**
19 </span> * @class Ext.util.Animate
20 * This animation class is a mixin.
22 * Ext.util.Animate provides an API for the creation of animated transitions of properties and styles.
23 * This class is used as a mixin and currently applied to {@link Ext.core.Element}, {@link Ext.CompositeElement},
24 * {@link Ext.draw.Sprite}, {@link Ext.draw.CompositeSprite}, and {@link Ext.Component}. Note that Components
25 * have a limited subset of what attributes can be animated such as top, left, x, y, height, width, and
26 * opacity (color, paddings, and margins can not be animated).
30 * All animations require three things - `easing`, `duration`, and `to` (the final end value for each property)
31 * you wish to animate. Easing and duration are defaulted values specified below.
32 * Easing describes how the intermediate values used during a transition will be calculated.
33 * {@link Ext.fx.Anim#easing Easing} allows for a transition to change speed over its duration.
34 * You may use the defaults for easing and duration, but you must always set a
35 * {@link Ext.fx.Anim#to to} property which is the end value for all animations.
37 * Popular element 'to' configurations are:
46 * Popular sprite 'to' configurations are:
54 * The default duration for animations is 250 (which is a 1/4 of a second). Duration is denoted in
55 * milliseconds. Therefore 1 second is 1000, 1 minute would be 60000, and so on. The default easing curve
56 * used for all animations is 'ease'. Popular easing functions are included and can be found in {@link Ext.fx.Anim#easing Easing}.
58 * For example, a simple animation to fade out an element with a default easing and duration:
60 * var p1 = Ext.get('myElementId');
68 * To make this animation fade out in a tenth of a second:
70 * var p1 = Ext.get('myElementId');
81 * By default all animations are added to a queue which allows for animation via a chain-style API.
82 * For example, the following code will queue 4 animations which occur sequentially (one right after the other):
94 * backgroundColor: '#f00' //red
102 * You can change this behavior by calling the {@link Ext.util.Animate#syncFx syncFx} method and all
103 * subsequent animations for the specified target will be run concurrently (at the same time).
105 * p1.syncFx(); //this will make all animations run at the same time
117 * backgroundColor: '#f00' //red
125 * This works the same as:
131 * backgroundColor: '#f00' //red
136 * The {@link Ext.util.Animate#stopAnimation stopAnimation} method can be used to stop any
137 * currently running animations and clear any queued animations.
139 * ## Animation Keyframes
141 * You can also set up complex animations with {@link Ext.fx.Anim#keyframe keyframe} which follows the
142 * CSS3 Animation configuration pattern. Note rotation, translation, and scaling can only be done for sprites.
143 * The previous example can be written with the following syntax:
146 * duration: 1000, //one second total
148 * 25: { //from 0 to 250ms (25%)
151 * 50: { //from 250ms to 500ms (50%)
154 * 75: { //from 500ms to 750ms (75%)
155 * backgroundColor: '#f00' //red
157 * 100: { //from 750ms to 1sec
163 * ## Animation Events
165 * Each animation you create has events for {@link Ext.fx.Anim#beforeanimation beforeanimation},
166 * {@link Ext.fx.Anim#afteranimate afteranimate}, and {@link Ext.fx.Anim#lastframe lastframe}.
167 * Keyframed animations adds an additional {@link Ext.fx.Animator#keyframe keyframe} event which
168 * fires for each keyframe in your animation.
170 * All animations support the {@link Ext.util.Observable#listeners listeners} configuration to attact functions to these events.
172 * startAnimate: function() {
173 * var p1 = Ext.get('myElementId');
180 * beforeanimate: function() {
181 * // Execute my custom method before the animation
182 * this.myBeforeAnimateFn();
184 * afteranimate: function() {
185 * // Execute my custom method after the animation
186 * this.myAfterAnimateFn();
191 * myBeforeAnimateFn: function() {
194 * myAfterAnimateFn: function() {
198 * Due to the fact that animations run asynchronously, you can determine if an animation is currently
199 * running on any target by using the {@link Ext.util.Animate#getActiveAnimation getActiveAnimation}
200 * method. This method will return false if there are no active animations or return the currently
201 * running {@link Ext.fx.Anim} instance.
203 * In this example, we're going to wait for the current animation to finish, then stop any other
204 * queued animations before we fade our element's opacity to 0:
206 * var curAnim = p1.getActiveAnimation();
208 * curAnim.on('afteranimate', function() {
209 * p1.stopAnimation();
218 * @docauthor Jamie Avins <jamie@sencha.com>
220 Ext.define('Ext.util.Animate', {
222 uses: ['Ext.fx.Manager', 'Ext.fx.Anim'],
224 <span id='Ext-util-Animate-method-animate'> /**
225 </span> * <p>Perform custom animation on this object.<p>
226 * <p>This method is applicable to both the {@link Ext.Component Component} class and the {@link Ext.core.Element Element} class.
227 * It performs animated transitions of certain properties of this object over a specified timeline.</p>
228 * <p>The sole parameter is an object which specifies start property values, end property values, and properties which
229 * describe the timeline. Of the properties listed below, only <b><code>to</code></b> is mandatory.</p>
230 * <p>Properties include<ul>
231 * <li><code>from</code> <div class="sub-desc">An object which specifies start values for the properties being animated.
232 * If not supplied, properties are animated from current settings. The actual properties which may be animated depend upon
233 * ths object being animated. See the sections below on Element and Component animation.<div></li>
234 * <li><code>to</code> <div class="sub-desc">An object which specifies end values for the properties being animated.</div></li>
235 * <li><code>duration</code><div class="sub-desc">The duration <b>in milliseconds</b> for which the animation will run.</div></li>
236 * <li><code>easing</code> <div class="sub-desc">A string value describing an easing type to modify the rate of change from the default linear to non-linear. Values may be one of:<code><ul>
237 * <li>ease</li>
238 * <li>easeIn</li>
239 * <li>easeOut</li>
240 * <li>easeInOut</li>
241 * <li>backIn</li>
242 * <li>backOut</li>
243 * <li>elasticIn</li>
244 * <li>elasticOut</li>
245 * <li>bounceIn</li>
246 * <li>bounceOut</li>
247 * </ul></code></div></li>
248 * <li><code>keyframes</code> <div class="sub-desc">This is an object which describes the state of animated properties at certain points along the timeline.
249 * it is an object containing properties who's names are the percentage along the timeline being described and who's values specify the animation state at that point.</div></li>
250 * <li><code>listeners</code> <div class="sub-desc">This is a standard {@link Ext.util.Observable#listeners listeners} configuration object which may be used
251 * to inject behaviour at either the <code>beforeanimate</code> event or the <code>afteranimate</code> event.</div></li>
252 * </ul></p>
253 * <h3>Animating an {@link Ext.core.Element Element}</h3>
254 * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
255 * <li><code>x</code> <div class="sub-desc">The page X position in pixels.</div></li>
256 * <li><code>y</code> <div class="sub-desc">The page Y position in pixels</div></li>
257 * <li><code>left</code> <div class="sub-desc">The element's CSS <code>left</code> value. Units must be supplied.</div></li>
258 * <li><code>top</code> <div class="sub-desc">The element's CSS <code>top</code> value. Units must be supplied.</div></li>
259 * <li><code>width</code> <div class="sub-desc">The element's CSS <code>width</code> value. Units must be supplied.</div></li>
260 * <li><code>height</code> <div class="sub-desc">The element's CSS <code>height</code> value. Units must be supplied.</div></li>
261 * <li><code>scrollLeft</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
262 * <li><code>scrollTop</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
263 * <li><code>opacity</code> <div class="sub-desc">The element's <code>opacity</code> value. This must be a value between <code>0</code> and <code>1</code>.</div></li>
265 * <p><b>Be aware than animating an Element which is being used by an Ext Component without in some way informing the Component about the changed element state
266 * will result in incorrect Component behaviour. This is because the Component will be using the old state of the element. To avoid this problem, it is now possible to
267 * directly animate certain properties of Components.</b></p>
268 * <h3>Animating a {@link Ext.Component Component}</h3>
269 * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
270 * <li><code>x</code> <div class="sub-desc">The Component's page X position in pixels.</div></li>
271 * <li><code>y</code> <div class="sub-desc">The Component's page Y position in pixels</div></li>
272 * <li><code>left</code> <div class="sub-desc">The Component's <code>left</code> value in pixels.</div></li>
273 * <li><code>top</code> <div class="sub-desc">The Component's <code>top</code> value in pixels.</div></li>
274 * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
275 * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
276 * <li><code>dynamic</code> <div class="sub-desc">Specify as true to update the Component's layout (if it is a Container) at every frame
277 * of the animation. <i>Use sparingly as laying out on every intermediate size change is an expensive operation</i>.</div></li>
279 * <p>For example, to animate a Window to a new size, ensuring that its internal layout, and any shadow is correct:</p>
280 * <pre><code>
281 myWindow = Ext.create('Ext.window.Window', {
282 title: 'Test Component animation',
300 myWindow.header.el.on('click', function() {
303 width: (myWindow.getWidth() == 500) ? 700 : 500,
304 height: (myWindow.getHeight() == 300) ? 400 : 300,
308 </code></pre>
309 * <p>For performance reasons, by default, the internal layout is only updated when the Window reaches its final <code>"to"</code> size. If dynamic updating of the Window's child
310 * Components is required, then configure the animation with <code>dynamic: true</code> and the two child items will maintain their proportions during the animation.</p>
311 * @param {Object} config An object containing properties which describe the animation's start and end states, and the timeline of the animation.
312 * @return {Object} this
314 animate: function(animObj) {
316 if (Ext.fx.Manager.hasFxBlock(me.id)) {
319 Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(animObj)));
323 // @private - process the passed fx configuration.
324 anim: function(config) {
325 if (!Ext.isObject(config)) {
326 return (config) ? {} : false;
331 if (config.stopAnimation) {
335 Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
343 <span id='Ext-util-Animate-method-stopFx'> /**
344 </span> * @deprecated 4.0 Replaced by {@link #stopAnimation}
345 * Stops any running effects and clears this object's internal effects queue if it contains
346 * any additional effects that haven't started yet.
347 * @return {Ext.core.Element} The Element
350 stopFx: Ext.Function.alias(Ext.util.Animate, 'stopAnimation'),
352 <span id='Ext-util-Animate-method-stopAnimation'> /**
353 </span> * Stops any running effects and clears this object's internal effects queue if it contains
354 * any additional effects that haven't started yet.
355 * @return {Ext.core.Element} The Element
357 stopAnimation: function() {
358 Ext.fx.Manager.stopAnimation(this.id);
362 <span id='Ext-util-Animate-method-syncFx'> /**
363 </span> * Ensures that all effects queued after syncFx is called on this object are
364 * run concurrently. This is the opposite of {@link #sequenceFx}.
365 * @return {Object} this
368 Ext.fx.Manager.setFxDefaults(this.id, {
374 <span id='Ext-util-Animate-method-sequenceFx'> /**
375 </span> * Ensures that all effects queued after sequenceFx is called on this object are
376 * run in sequence. This is the opposite of {@link #syncFx}.
377 * @return {Object} this
379 sequenceFx: function() {
380 Ext.fx.Manager.setFxDefaults(this.id, {
386 <span id='Ext-util-Animate-method-hasActiveFx'> /**
387 </span> * @deprecated 4.0 Replaced by {@link #getActiveAnimation}
388 * Returns thq current animation if this object has any effects actively running or queued, else returns false.
389 * @return {Mixed} anim if element has active effects, else false
392 hasActiveFx: Ext.Function.alias(Ext.util.Animate, 'getActiveAnimation'),
394 <span id='Ext-util-Animate-method-getActiveAnimation'> /**
395 </span> * Returns thq current animation if this object has any effects actively running or queued, else returns false.
396 * @return {Mixed} anim if element has active effects, else false
398 getActiveAnimation: function() {
399 return Ext.fx.Manager.getActiveAnimation(this.id);
402 // Apply Animate mixin manually until Element is defined in the proper 4.x way
403 Ext.applyIf(Ext.core.Element.prototype, this.prototype);
404 // We need to call this again so the animation methods get copied over to CE
405 Ext.CompositeElementLite.importElementMethods();