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-fx.Anim'>/**
2 </span> * @class Ext.fx.Anim
4 * This class manages animation for a specific {@link #target}. The animation allows
5 * animation of various properties on the target, such as size, position, color and others.
7 * ## Starting Conditions
8 * The starting conditions for the animation are provided by the {@link #from} configuration.
9 * Any/all of the properties in the {@link #from} configuration can be specified. If a particular
10 * property is not defined, the starting value for that property will be read directly from the target.
13 * The ending conditions for the animation are provided by the {@link #to} configuration. These mark
14 * the final values once the animations has finished. The values in the {@link #from} can mirror
15 * those in the {@link #to} configuration to provide a starting point.
18 * - {@link #duration}: Specifies the time period of the animation.
19 * - {@link #easing}: Specifies the easing of the animation.
20 * - {@link #iterations}: Allows the animation to repeat a number of times.
21 * - {@link #alternate}: Used in conjunction with {@link #iterations}, reverses the direction every second iteration.
25 * var myComponent = Ext.create('Ext.Component', {
26 * renderTo: document.body,
29 * style: 'border: 1px solid red;'
33 * target: myComponent,
36 * width: 400 //starting width 400
39 * width: 300, //end width 300
40 * height: 300 // end width 300
44 Ext.define('Ext.fx.Anim', {
46 /* Begin Definitions */
49 observable: 'Ext.util.Observable'
52 requires: ['Ext.fx.Manager', 'Ext.fx.Animator', 'Ext.fx.Easing', 'Ext.fx.CubicBezier', 'Ext.fx.PropertyHandler'],
57 <span id='Ext-fx.Anim-cfg-duration'> /**
58 </span> * @cfg {Number} duration
59 * Time in milliseconds for a single animation to last. Defaults to 250. If the {@link #iterations} property is
60 * specified, then each animate will take the same duration for each iteration.
64 <span id='Ext-fx.Anim-cfg-delay'> /**
65 </span> * @cfg {Number} delay
66 * Time to delay before starting the animation. Defaults to 0.
70 /* private used to track a delayed starting time */
73 <span id='Ext-fx.Anim-cfg-dynamic'> /**
74 </span> * @cfg {Boolean} dynamic
75 * Currently only for Component Animation: Only set a component's outer element size bypassing layouts. Set to true to do full layouts for every frame of the animation. Defaults to false.
79 <span id='Ext-fx.Anim-cfg-easing'> /**
80 </span> * @cfg {String} easing
81 This describes how the intermediate values used during a transition will be calculated. It allows for a transition to change
82 speed over its duration.
94 -cubic-bezier(x1, y1, x2, y2)
96 Note that cubic-bezier will create a custom easing curve following the CSS3 transition-timing-function specification `{@link http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag}`. The four values specify points P1 and P2 of the curve
97 as (x1, y1, x2, y2). All values must be in the range [0, 1] or the definition is invalid.
102 <span id='Ext-fx.Anim-cfg-keyframes'> /**
103 </span> * @cfg {Object} keyframes
104 * Animation keyframes follow the CSS3 Animation configuration pattern. 'from' is always considered '0%' and 'to'
105 * is considered '100%'.<b>Every keyframe declaration must have a keyframe rule for 0% and 100%, possibly defined using
106 * "from" or "to"</b>. A keyframe declaration without these keyframe selectors is invalid and will not be available for
107 * animation. The keyframe declaration for a keyframe rule consists of properties and values. Properties that are unable to
108 * be animated are ignored in these rules, with the exception of 'easing' which can be changed at each keyframe. For example:
109 <pre><code>
124 </code></pre>
127 <span id='Ext-fx.Anim-property-damper'> /**
132 <span id='Ext-fx.Anim-property-bezierRE'> /**
135 bezierRE: /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
137 <span id='Ext-fx.Anim-cfg-reverse'> /**
138 </span> * Run the animation from the end to the beginning
140 * @cfg {Boolean} reverse
144 <span id='Ext-fx.Anim-property-running'> /**
145 </span> * Flag to determine if the animation has started
151 <span id='Ext-fx.Anim-property-paused'> /**
152 </span> * Flag to determine if the animation is paused. Only set this to true if you need to
153 * keep the Anim instance around to be unpaused later; otherwise call {@link #end}.
159 <span id='Ext-fx.Anim-cfg-iterations'> /**
160 </span> * Number of times to execute the animation. Defaults to 1.
161 * @cfg {int} iterations
165 <span id='Ext-fx.Anim-cfg-alternate'> /**
166 </span> * Used in conjunction with iterations to reverse the animation each time an iteration completes.
167 * @cfg {Boolean} alternate
172 <span id='Ext-fx.Anim-property-currentIteration'> /**
173 </span> * Current iteration the animation is running.
174 * @property currentIteration
179 <span id='Ext-fx.Anim-property-startTime'> /**
180 </span> * Starting time of the animation.
181 * @property startTime
186 <span id='Ext-fx.Anim-property-propHandlers'> /**
187 </span> * Contains a cache of the interpolators to be used.
189 * @property propHandlers
193 <span id='Ext-fx.Anim-cfg-target'> /**
194 </span> * @cfg {String/Object} target
195 * The {@link Ext.fx.target.Target} to apply the animation to. This should only be specified when creating an Ext.fx.Anim directly.
196 * The target does not need to be a {@link Ext.fx.target.Target} instance, it can be the underlying object. For example, you can
197 * pass a Component, Element or Sprite as the target and the Anim will create the appropriate {@link Ext.fx.target.Target} object
201 <span id='Ext-fx.Anim-cfg-from'> /**
202 </span> * @cfg {Object} from
203 * An object containing property/value pairs for the beginning of the animation. If not specified, the current state of the
204 * Ext.fx.target will be used. For example:
205 <pre><code>
207 opacity: 0, // Transparent
208 color: '#ffffff', // White
211 </code></pre>
214 <span id='Ext-fx.Anim-cfg-to'> /**
215 </span> * @cfg {Object} to
216 * An object containing property/value pairs for the end of the animation. For example:
217 <pre><code>
219 opacity: 1, // Opaque
220 color: '#00ff00', // Green
223 </code></pre>
227 constructor: function(config) {
229 config = config || {};
230 // If keyframes are passed, they really want an Animator instead.
231 if (config.keyframes) {
232 return Ext.create('Ext.fx.Animator', config);
234 config = Ext.apply(me, config);
235 if (me.from === undefined) {
238 me.propHandlers = {};
240 me.target = Ext.fx.Manager.createTarget(me.target);
241 me.easingFn = Ext.fx.Easing[me.easing];
242 me.target.dynamic = me.dynamic;
244 // If not a pre-defined curve, try a cubic-bezier
246 me.easingFn = String(me.easing).match(me.bezierRE);
247 if (me.easingFn && me.easingFn.length == 5) {
248 var curve = me.easingFn;
249 me.easingFn = Ext.fx.cubicBezier(+curve[1], +curve[2], +curve[3], +curve[4]);
252 me.id = Ext.id(null, 'ext-anim-');
253 Ext.fx.Manager.addAnim(me);
255 <span id='Ext-fx.Anim-event-beforeanimate'> /**
256 </span> * @event beforeanimate
257 * Fires before the animation starts. A handler can return false to cancel the animation.
258 * @param {Ext.fx.Anim} this
261 <span id='Ext-fx.Anim-event-afteranimate'> /**
262 </span> * @event afteranimate
263 * Fires when the animation is complete.
264 * @param {Ext.fx.Anim} this
265 * @param {Date} startTime
268 <span id='Ext-fx.Anim-event-lastframe'> /**
269 </span> * @event lastframe
270 * Fires when the animation's last frame has been set.
271 * @param {Ext.fx.Anim} this
272 * @param {Date} startTime
276 me.mixins.observable.constructor.call(me, config);
277 if (config.callback) {
278 me.on('afteranimate', config.callback, config.scope);
283 <span id='Ext-fx.Anim-method-setAttr'> /**
285 * Helper to the target
287 setAttr: function(attr, value) {
288 return Ext.fx.Manager.items.get(this.id).setAttr(this.target, attr, value);
293 * Set up the initial currentAttrs hash.
295 initAttrs: function() {
299 initialFrom = me.initialFrom || {},
301 start, end, propHandler, attr;
304 if (to.hasOwnProperty(attr)) {
305 start = me.target.getAttr(attr, from[attr]);
307 // Use default (numeric) property handler
308 if (!Ext.fx.PropertyHandler[attr]) {
309 if (Ext.isObject(end)) {
310 propHandler = me.propHandlers[attr] = Ext.fx.PropertyHandler.object;
312 propHandler = me.propHandlers[attr] = Ext.fx.PropertyHandler.defaultHandler;
315 // Use custom handler
317 propHandler = me.propHandlers[attr] = Ext.fx.PropertyHandler[attr];
319 out[attr] = propHandler.get(start, end, me.damper, initialFrom[attr], attr);
322 me.currentAttrs = out;
327 * Fires beforeanimate and sets the running flag.
329 start: function(startTime) {
332 delayStart = me.delayStart,
336 me.delayStart = startTime;
340 delayDelta = startTime - delayStart;
341 if (delayDelta < delay) {
345 // Compensate for frame delay;
346 startTime = new Date(delayStart.getTime() + delay);
350 if (me.fireEvent('beforeanimate', me) !== false) {
351 me.startTime = startTime;
352 if (!me.paused && !me.currentAttrs) {
361 * Calculate attribute value at the passed timestamp.
362 * @returns a hash of the new attributes.
364 runAnim: function(elapsedTime) {
366 attrs = me.currentAttrs,
367 duration = me.duration,
368 easingFn = me.easingFn,
369 propHandlers = me.propHandlers,
371 easing, values, attr, lastFrame;
373 if (elapsedTime >= duration) {
374 elapsedTime = duration;
378 elapsedTime = duration - elapsedTime;
381 for (attr in attrs) {
382 if (attrs.hasOwnProperty(attr)) {
383 values = attrs[attr];
384 easing = lastFrame ? 1 : easingFn(elapsedTime / duration);
385 ret[attr] = propHandlers[attr].set(values, easing);
393 * Perform lastFrame cleanup and handle iterations
394 * @returns a hash of the new attributes.
396 lastFrame: function() {
398 iter = me.iterations,
399 iterCount = me.currentIteration;
402 if (iterCount < iter) {
404 me.reverse = !me.reverse;
406 me.startTime = new Date();
407 me.currentIteration = iterCount;
408 // Turn off paused for CSS3 Transitions
412 me.currentIteration = 0;
414 me.fireEvent('lastframe', me, me.startTime);
419 * Fire afteranimate event and end the animation. Usually called automatically when the
420 * animation reaches its final frame, but can also be called manually to pre-emptively
421 * stop and destroy the running animation.
428 Ext.fx.Manager.removeAnim(me);
429 me.fireEvent('afteranimate', me, me.startTime);
432 // Set flag to indicate that Fx is available. Class might not be available immediately.
434 </pre></pre></body></html>