📄 fx.js
字号:
if(!dojo._hasResource["dojo._base.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojo._base.fx"] = true;dojo.provide("dojo._base.fx");dojo.require("dojo._base.Color");dojo.require("dojo._base.connect");dojo.require("dojo._base.declare");dojo.require("dojo._base.lang");dojo.require("dojo._base.html");/* Animation losely package based on Dan Pupius' work, contributed under CLA: http://pupius.co.uk/js/Toolkit.Drawing.js*/(function(){ var d = dojo; dojo._Line = function(/*int*/ start, /*int*/ end){ // summary: // dojo._Line is the object used to generate values from a start value // to an end value // start: int // Beginning value for range // end: int // Ending value for range this.start = start; this.end = end; this.getValue = function(/*float*/ n){ // summary: returns the point on the line // n: a floating point number greater than 0 and less than 1 return ((this.end - this.start) * n) + this.start; // Decimal } } d.declare("dojo._Animation", null, { // summary // A generic animation class that fires callbacks into its handlers // object at various states. Nearly all dojo animation functions // return an instance of this method, usually without calling the // .play() method beforehand. Therefore, you will likely need to // call .play() on instances of dojo._Animation when one is // returned. constructor: function(/*Object*/ args){ d.mixin(this, args); if(d.isArray(this.curve)){ /* curve: Array pId: a */ this.curve = new d._Line(this.curve[0], this.curve[1]); } }, // duration: Integer // The time in milliseonds the animation will take to run duration: 350, /*===== // curve: dojo._Line||Array // A two element array of start and end values, or a dojo._Line instance to be // used in the Animation. curve: null, // easing: Function // A Function to adjust the acceleration (or deceleration) of the progress // across a dojo._Line easing: null, =====*/ // repeat: Integer // The number of times to loop the animation repeat: 0, // rate: Integer // the time in milliseconds to wait before advancing to next frame // (used as a fps timer: rate/1000 = fps) rate: 10 /* 100 fps */, /*===== // delay: Integer // The time in milliseconds to wait before starting animation after it has been .play()'ed delay: null, // events // // beforeBegin: Event // Synthetic event fired before a dojo._Animation begins playing (synchronous) beforeBegin: null, // onBegin: Event // Synthetic event fired as a dojo._Animation begins playing (useful?) onBegin: null, // onAnimate: Event // Synthetic event fired at each interval of a dojo._Animation onAnimate: null, // onEnd: Event // Synthetic event fired after the final frame of a dojo._Animation onEnd: null, // onPlay: Event // Synthetic event fired any time a dojo._Animation is play()'ed onPlay: null, // onPause: Event // Synthetic event fired when a dojo._Animation is paused onPause: null, // onStop: Event // Synthetic event fires when a dojo._Animation is stopped onStop: null, =====*/ _percent: 0, _startRepeatCount: 0, _fire: function(/*Event*/ evt, /*Array?*/ args){ // summary: // Convenience function. Fire event "evt" and pass it the // arguments specified in "args". // evt: // The event to fire. // args: // The arguments to pass to the event. try{ if(this[evt]){ this[evt].apply(this, args||[]); } }catch(e){ // squelch and log because we shouldn't allow exceptions in // synthetic event handlers to cause the internal timer to run // amuck, potentially pegging the CPU. I'm not a fan of this // squelch, but hopefully logging will make it clear what's // going on console.error("exception in animation handler for:", evt); console.error(e); } return this; // dojo._Animation }, play: function(/*int?*/ delay, /*Boolean?*/ gotoStart){ // summary: // Start the animation. // delay: // How many milliseconds to delay before starting. // gotoStart: // If true, starts the animation from the beginning; otherwise, // starts it from its current position. var _t = this; if(gotoStart){ _t._stopTimer(); _t._active = _t._paused = false; _t._percent = 0; }else if(_t._active && !_t._paused){ return _t; // dojo._Animation } _t._fire("beforeBegin"); var de = delay||_t.delay; var _p = dojo.hitch(_t, "_play", gotoStart); if(de > 0){ setTimeout(_p, de); return _t; // dojo._Animation } _p(); return _t; }, _play: function(gotoStart){ var _t = this; _t._startTime = new Date().valueOf(); if(_t._paused){ _t._startTime -= _t.duration * _t._percent; } _t._endTime = _t._startTime + _t.duration; _t._active = true; _t._paused = false; var value = _t.curve.getValue(_t._percent); if(!_t._percent){ if(!_t._startRepeatCount){ _t._startRepeatCount = _t.repeat; } _t._fire("onBegin", [value]); } _t._fire("onPlay", [value]); _t._cycle(); return _t; // dojo._Animation }, pause: function(){ // summary: Pauses a running animation. this._stopTimer(); if(!this._active){ return this; /*dojo._Animation*/ } this._paused = true; this._fire("onPause", [this.curve.getValue(this._percent)]); return this; // dojo._Animation }, gotoPercent: function(/*Decimal*/ percent, /*Boolean?*/ andPlay){ // summary: // Sets the progress of the animation. // percent: // A percentage in decimal notation (between and including 0.0 and 1.0). // andPlay: // If true, play the animation after setting the progress. this._stopTimer(); this._active = this._paused = true; this._percent = percent; if(andPlay){ this.play(); } return this; // dojo._Animation }, stop: function(/*boolean?*/ gotoEnd){ // summary: Stops a running animation. // gotoEnd: If true, the animation will end. if(!this._timer){ return this; /* dojo._Animation */ } this._stopTimer(); if(gotoEnd){ this._percent = 1; } this._fire("onStop", [this.curve.getValue(this._percent)]); this._active = this._paused = false; return this; // dojo._Animation }, status: function(){ // summary: Returns a string token representation of the status of // the animation, one of: "paused", "playing", "stopped" if(this._active){ return this._paused ? "paused" : "playing"; // String } return "stopped"; // String }, _cycle: function(){ var _t = this; if(_t._active){ var curr = new Date().valueOf(); var step = (curr - _t._startTime) / (_t._endTime - _t._startTime); if(step >= 1){ step = 1; } _t._percent = step; // Perform easing if(_t.easing){ step = _t.easing(step); } _t._fire("onAnimate", [_t.curve.getValue(step)]); if(_t._percent < 1){ _t._startTimer(); }else{ _t._active = false; if(_t.repeat > 0){ _t.repeat--; _t.play(null, true); }else if(_t.repeat == -1){ _t.play(null, true); }else{ if(_t._startRepeatCount){ _t.repeat = _t._startRepeatCount; _t._startRepeatCount = 0; } } _t._percent = 0; _t._fire("onEnd"); _t._stopTimer(); } } return _t; // dojo._Animation } }); var ctr = 0; var _globalTimerList = []; var runner = { run: function(){ } }; var timer = null; dojo._Animation.prototype._startTimer = function(){ // this._timer = setTimeout(dojo.hitch(this, "_cycle"), this.rate); if(!this._timer){ this._timer = d.connect(runner, "run", this, "_cycle"); ctr++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -