animator.js
来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 484 行 · 第 1/2 页
JS
484 行
/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/**
* @class Ext.Animator
* Provides support for syncing animations for multiple {@link Ext.Actor}s.<br><br>
* <br><br>This example can be seen in action <a href="http://www.jackslocum.com/yui/2006/08/19/a-splitbar-component-for-yahoo-ui/" target="_new">here</a>
* by clicking on "Click here and I will point it out" at the end of the first paragraph.<br>
* <pre><code>
var animator = new Ext.Animator();
var cursor = new Ext.Actor("cursor-img", animator);
var click = new Ext.Actor("click-img", animator);
var resize = new Ext.Actor("resize-img", animator);
// start capturing
animator.startCapture();
// these animations will be run in sequence
cursor.show();
cursor.moveTo(500,400);
cursor.moveTo(20, Ext.get("navbar").getY()+10, true, .75);
click.show();
click.alignTo(cursor, "tl", [-4, -4]);
// Add an async function call, pass callback to argument 1
animator.addAsyncCall(Blog.navbar.undockDelegate, 1);
// pause .5 seconds
animator.pause(.5);
// again, these animations will be run in sequence
click.hide(true, .7);
cursor.alignTo("splitter", "tr", [0, +100], true, 1);
resize.alignTo("splitter", "tr", [-12, +100]);
// start sync block: these animations will run at the same time
animator.beginSync();
cursor.hide();
resize.show();
animator.endSync();
// play the captured animation sequences, call myCallback when done
animator.play(myCallback);
* </code></pre>
* @requires Ext.Element
* @requires YAHOO.util.Dom
* @requires YAHOO.util.Event
* @requires YAHOO.util.CustomEvent
* @requires YAHOO.util.Anim
* @requires YAHOO.util.ColorAnim
* @requires YAHOO.util.Motion
* @constructor
* @param {String/HTMLElement} el The dom element or element id
* @param {Ext.Animator} animator (optional) The Animator that will capture this Actor's actions
* @param {Boolean} selfCapture (optional) Whether this actor should capture its own actions to support self playback without an animator (defaults to false)
*/
Ext.Animator = function(/*Actors...*/){
this.actors = [];
this.playlist = new Ext.Animator.AnimSequence();
this.captureDelegate = this.capture.createDelegate(this);
this.playDelegate = this.play.createDelegate(this);
this.syncing = false;
this.stopping = false;
this.playing = false;
for(var i = 0; i < arguments.length; i++){
this.addActor(arguments[i]);
}
};
Ext.Animator.prototype = {
capture : function(actor, action){
if(this.syncing){
if(!this.syncMap[actor.id]){
this.syncMap[actor.id] = new Ext.Animator.AnimSequence();
}
this.syncMap[actor.id].add(action);
}else{
this.playlist.add(action);
}
},
/**
* Add an actor. The actor is also set to capturing = true.
* @param {Ext.Actor} actor
*/
addActor : function(actor){
actor.onCapture.addListener(this.captureDelegate);
this.actors.push(actor);
},
/**
* Start capturing actions on the added actors.
* @param {Boolean} clearPlaylist Whether to also create a new playlist
*/
startCapture : function(clearPlaylist){
for(var i = 0; i < this.actors.length; i++){
var a = this.actors[i];
if(!this.isCapturing(a)){
a.onCapture.addListener(this.captureDelegate);
}
a.capturing = true;
}
if(clearPlaylist){
this.playlist = new Ext.Animator.AnimSequence();
}
},
/**
* Checks whether this animator is listening to a specific actor.
* @param {Ext.Actor} actor
*/
isCapturing : function(actor){
return actor.onCapture.isListening(this.captureDelegate);
},
/**
* Stop capturing on all added actors.
*/
stopCapture : function(){
for(var i = 0; i < this.actors.length; i++){
var a = this.actors[i];
a.onCapture.removeListener(this.captureDelegate);
a.capturing = false;
}
},
/**
* Start a multi-actor sync block. By default all animations are run in sequence. While in the sync block
* each actor's own animations will still be sequenced, but all actors will animate at the same time.
*/
beginSync : function(){
this.syncing = true;
this.syncMap = {};
},
/**
* End the multi-actor sync block
*/
endSync : function(){
this.syncing = false;
var composite = new Ext.Animator.CompositeSequence();
for(key in this.syncMap){
if(typeof this.syncMap[key] != "function"){
composite.add(this.syncMap[key]);
}
}
this.playlist.add(composite);
this.syncMap = null;
},
/**
* Starts playback of the playlist, also stops any capturing. To start capturing again call {@link #startCapture}.
* @param {Function} oncomplete (optional) Callback to execute when playback has completed
*/
play : function(oncomplete){
if(this.playing) return; // can't play the same animation twice at once
this.stopCapture();
this.playlist.play(oncomplete);
},
/**
* Stop at the next available stopping point
*/
stop : function(){
this.playlist.stop();
},
/**
* Check if this animator is currently playing
*/
isPlaying : function(){
return this.playlist.isPlaying();
},
/**
* Clear the playlist
*/
clear : function(){
this.playlist = new Ext.Animator.AnimSequence();
},
/**
* Add a function call to the playlist.
* @param {Function} fcn The function to call
* @param {Array} args The arguments to call the function with
* @param {Object} scope (optional) The scope of the function
*/
addCall : function(fcn, args, scope){
this.playlist.add(new Ext.Actor.Action(scope, fcn, args || []));
},
/**
* Add an async function call to the playlist.
* @param {Function} fcn The function to call
* @param {Number} callbackIndex The index of the callback parameter on the passed function. A CALLBACK IS REQUIRED.
* @param {Array} args The arguments to call the function with
* @param {Object} scope (optional) The scope of the function
*/
addAsyncCall : function(fcn, callbackIndex, args, scope){
this.playlist.add(new Ext.Actor.AsyncAction(scope, fcn, args || [], callbackIndex));
},
/**
* Add a pause to the playlist (in seconds)
* @param {Number} seconds The number of seconds to pause.
*/
pause : function(seconds){
this.playlist.add(new Ext.Actor.PauseAction(seconds));
}
};
/**
* Static function to build a AnimatorComposite from a css selector (requires Ext.Element.selectorFunction be defined)
* @param {String/Array} selector The css selector or an array of nodes to animate
* @method @static
*/
Ext.Animator.select = function(selector){
var els;
if(typeof selector == "string"){
els = Ext.Element.selectorFunction(selector);
}else if(selector instanceof Array){
els = selector;
}else{
throw "Invalid selector";
}
return new Ext.AnimatorComposite(els);
};
//var getActors = Ext.Animator.select;
Ext.actors = Ext.Animator.select;
/**
* @class Ext.AnimatorComposite
* Composite class with synchronized animations. This is the class returned by getActors(selector) or Ext.Animator.select().
*/
Ext.AnimatorComposite = function(els){
this.animator = new Ext.Animator();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?