1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.Animate'>/**
2 </span> * @class Ext.util.Animate
3 * This animation class is a mixin.
5 * Ext.util.Animate provides an API for the creation of animated transitions of properties and styles.
6 * This class is used as a mixin and currently applied to {@link Ext.core.Element}, {@link Ext.CompositeElement},
7 * {@link Ext.draw.Sprite}, {@link Ext.draw.CompositeSprite}, and {@link Ext.Component}. Note that Components
8 * have a limited subset of what attributes can be animated such as top, left, x, y, height, width, and
9 * opacity (color, paddings, and margins can not be animated).
13 * All animations require three things - `easing`, `duration`, and `to` (the final end value for each property)
14 * you wish to animate. Easing and duration are defaulted values specified below.
15 * Easing describes how the intermediate values used during a transition will be calculated.
16 * {@link Ext.fx.Anim#easing Easing} allows for a transition to change speed over its duration.
17 * You may use the defaults for easing and duration, but you must always set a
18 * {@link Ext.fx.Anim#to to} property which is the end value for all animations.
20 * Popular element 'to' configurations are:
29 * Popular sprite 'to' configurations are:
37 * The default duration for animations is 250 (which is a 1/4 of a second). Duration is denoted in
38 * milliseconds. Therefore 1 second is 1000, 1 minute would be 60000, and so on. The default easing curve
39 * used for all animations is 'ease'. Popular easing functions are included and can be found in {@link Ext.fx.Anim#easing Easing}.
41 * For example, a simple animation to fade out an element with a default easing and duration:
43 * var p1 = Ext.get('myElementId');
51 * To make this animation fade out in a tenth of a second:
53 * var p1 = Ext.get('myElementId');
64 * By default all animations are added to a queue which allows for animation via a chain-style API.
65 * For example, the following code will queue 4 animations which occur sequentially (one right after the other):
77 * backgroundColor: '#f00' //red
85 * You can change this behavior by calling the {@link Ext.util.Animate#syncFx syncFx} method and all
86 * subsequent animations for the specified target will be run concurrently (at the same time).
88 * p1.syncFx(); //this will make all animations run at the same time
100 * backgroundColor: '#f00' //red
108 * This works the same as:
114 * backgroundColor: '#f00' //red
119 * The {@link Ext.util.Animate#stopAnimation stopAnimation} method can be used to stop any
120 * currently running animations and clear any queued animations.
122 * ## Animation Keyframes
124 * You can also set up complex animations with {@link Ext.fx.Anim#keyframe keyframe} which follows the
125 * CSS3 Animation configuration pattern. Note rotation, translation, and scaling can only be done for sprites.
126 * The previous example can be written with the following syntax:
129 * duration: 1000, //one second total
131 * 25: { //from 0 to 250ms (25%)
134 * 50: { //from 250ms to 500ms (50%)
137 * 75: { //from 500ms to 750ms (75%)
138 * backgroundColor: '#f00' //red
140 * 100: { //from 750ms to 1sec
146 * ## Animation Events
148 * Each animation you create has events for {@link Ext.fx.Anim#beforeanimation beforeanimation},
149 * {@link Ext.fx.Anim#afteranimate afteranimate}, and {@link Ext.fx.Anim#lastframe lastframe}.
150 * Keyframed animations adds an additional {@link Ext.fx.Animator#keyframe keyframe} event which
151 * fires for each keyframe in your animation.
153 * All animations support the {@link Ext.util.Observable#listeners listeners} configuration to attact functions to these events.
155 * startAnimate: function() {
156 * var p1 = Ext.get('myElementId');
163 * beforeanimate: function() {
164 * // Execute my custom method before the animation
165 * this.myBeforeAnimateFn();
167 * afteranimate: function() {
168 * // Execute my custom method after the animation
169 * this.myAfterAnimateFn();
174 * myBeforeAnimateFn: function() {
177 * myAfterAnimateFn: function() {
181 * Due to the fact that animations run asynchronously, you can determine if an animation is currently
182 * running on any target by using the {@link Ext.util.Animate#getActiveAnimation getActiveAnimation}
183 * method. This method will return false if there are no active animations or return the currently
184 * running {@link Ext.fx.Anim} instance.
186 * In this example, we're going to wait for the current animation to finish, then stop any other
187 * queued animations before we fade our element's opacity to 0:
189 * var curAnim = p1.getActiveAnimation();
191 * curAnim.on('afteranimate', function() {
192 * p1.stopAnimation();
201 * @docauthor Jamie Avins <jamie@sencha.com>
203 Ext.define('Ext.util.Animate', {
205 uses: ['Ext.fx.Manager', 'Ext.fx.Anim'],
207 <span id='Ext-util.Animate-method-animate'> /**
208 </span> * <p>Perform custom animation on this object.<p>
209 * <p>This method is applicable to both the the {@link Ext.Component Component} class and the {@link Ext.core.Element Element} class.
210 * It performs animated transitions of certain properties of this object over a specified timeline.</p>
211 * <p>The sole parameter is an object which specifies start property values, end property values, and properties which
212 * describe the timeline. Of the properties listed below, only <b><code>to</code></b> is mandatory.</p>
213 * <p>Properties include<ul>
214 * <li><code>from</code> <div class="sub-desc">An object which specifies start values for the properties being animated.
215 * If not supplied, properties are animated from current settings. The actual properties which may be animated depend upon
216 * ths object being animated. See the sections below on Element and Component animation.<div></li>
217 * <li><code>to</code> <div class="sub-desc">An object which specifies end values for the properties being animated.</div></li>
218 * <li><code>duration</code><div class="sub-desc">The duration <b>in milliseconds</b> for which the animation will run.</div></li>
219 * <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>
220 * <li>ease</li>
221 * <li>easeIn</li>
222 * <li>easeOut</li>
223 * <li>easeInOut</li>
224 * <li>backIn</li>
225 * <li>backOut</li>
226 * <li>elasticIn</li>
227 * <li>elasticOut</li>
228 * <li>bounceIn</li>
229 * <li>bounceOut</li>
230 * </ul></code></div></li>
231 * <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.
232 * 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>
233 * <li><code>listeners</code> <div class="sub-desc">This is a standard {@link Ext.util.Observable#listeners listeners} configuration object which may be used
234 * to inject behaviour at either the <code>beforeanimate</code> event or the <code>afteranimate</code> event.</div></li>
235 * </ul></p>
236 * <h3>Animating an {@link Ext.core.Element Element}</h3>
237 * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
238 * <li><code>x</code> <div class="sub-desc">The page X position in pixels.</div></li>
239 * <li><code>y</code> <div class="sub-desc">The page Y position in pixels</div></li>
240 * <li><code>left</code> <div class="sub-desc">The element's CSS <code>left</code> value. Units must be supplied.</div></li>
241 * <li><code>top</code> <div class="sub-desc">The element's CSS <code>top</code> value. Units must be supplied.</div></li>
242 * <li><code>width</code> <div class="sub-desc">The element's CSS <code>width</code> value. Units must be supplied.</div></li>
243 * <li><code>height</code> <div class="sub-desc">The element's CSS <code>height</code> value. Units must be supplied.</div></li>
244 * <li><code>scrollLeft</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
245 * <li><code>scrollTop</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
246 * <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>
248 * <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
249 * 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
250 * directly animate certain properties of Components.</b></p>
251 * <h3>Animating a {@link Ext.Component Component}</h3>
252 * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
253 * <li><code>x</code> <div class="sub-desc">The Component's page X position in pixels.</div></li>
254 * <li><code>y</code> <div class="sub-desc">The Component's page Y position in pixels</div></li>
255 * <li><code>left</code> <div class="sub-desc">The Component's <code>left</code> value in pixels.</div></li>
256 * <li><code>top</code> <div class="sub-desc">The Component's <code>top</code> value in pixels.</div></li>
257 * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
258 * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
259 * <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
260 * of the animation. <i>Use sparingly as laying out on every intermediate size change is an expensive operation</i>.</div></li>
262 * <p>For example, to animate a Window to a new size, ensuring that its internal layout, and any shadow is correct:</p>
263 * <pre><code>
264 myWindow = Ext.create('Ext.window.Window', {
265 title: 'Test Component animation',
283 myWindow.header.el.on('click', function() {
286 width: (myWindow.getWidth() == 500) ? 700 : 500,
287 height: (myWindow.getHeight() == 300) ? 400 : 300,
291 </code></pre>
292 * <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
293 * 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>
294 * @param {Object} config An object containing properties which describe the animation's start and end states, and the timeline of the animation.
295 * @return {Object} this
297 animate: function(animObj) {
299 if (Ext.fx.Manager.hasFxBlock(me.id)) {
302 Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(animObj)));
306 // @private - process the passed fx configuration.
307 anim: function(config) {
308 if (!Ext.isObject(config)) {
309 return (config) ? {} : false;
314 if (config.stopAnimation) {
318 Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
326 <span id='Ext-util.Animate-property-stopFx'> /**
327 </span> * Stops any running effects and clears this object's internal effects queue if it contains
328 * any additional effects that haven't started yet.
329 * @return {Ext.core.Element} The Element
331 stopFx: Ext.Function.alias(Ext.util.Animate, 'stopAnimation'),
333 <span id='Ext-util.Animate-method-stopAnimation'> /**
334 </span> * @deprecated 4.0 Replaced by {@link #stopAnimation}
335 * Stops any running effects and clears this object's internal effects queue if it contains
336 * any additional effects that haven't started yet.
337 * @return {Ext.core.Element} The Element
339 stopAnimation: function() {
340 Ext.fx.Manager.stopAnimation(this.id);
343 <span id='Ext-util.Animate-method-syncFx'> /**
344 </span> * Ensures that all effects queued after syncFx is called on this object are
345 * run concurrently. This is the opposite of {@link #sequenceFx}.
346 * @return {Ext.core.Element} The Element
349 Ext.fx.Manager.setFxDefaults(this.id, {
354 <span id='Ext-util.Animate-method-sequenceFx'> /**
355 </span> * Ensures that all effects queued after sequenceFx is called on this object are
356 * run in sequence. This is the opposite of {@link #syncFx}.
357 * @return {Ext.core.Element} The Element
359 sequenceFx: function() {
360 Ext.fx.Manager.setFxDefaults(this.id, {
365 <span id='Ext-util.Animate-property-hasActiveFx'> /**
366 </span> * @deprecated 4.0 Replaced by {@link #getActiveAnimation}
367 * Returns thq current animation if this object has any effects actively running or queued, else returns false.
368 * @return {Mixed} anim if element has active effects, else false
370 hasActiveFx: Ext.Function.alias(Ext.util.Animate, 'getActiveAnimation'),
372 <span id='Ext-util.Animate-method-getActiveAnimation'> /**
373 </span> * Returns thq current animation if this object has any effects actively running or queued, else returns false.
374 * @return {Mixed} anim if element has active effects, else false
376 getActiveAnimation: function() {
377 return Ext.fx.Manager.getActiveAnimation(this.id);
381 // Apply Animate mixin manually until Element is defined in the proper 4.x way
382 Ext.applyIf(Ext.core.Element.prototype, Ext.util.Animate.prototype);</pre></pre></body></html>