📄 animation.js
字号:
if (error != null) { this.logWarn("Attempt to fire registered animation:" + isc.Log.echoAll(entry) + "\nCaused an error:"+ (error.message ? error.message : error)); // delete it, so even if its time hasn't elapsed we don't run into this error // repeatedly until the time expires this.registry[i] = null; } if (unbiasedRatio >= 1) { this.logDebug("animation " + entry.ID + " completed", "animation"); } } this.registry.removeEmpty(); // Stop looping if we don't have any pending animations if (this.registry.length == 0) { isc.Timer.clearTimeout(this._animationTimer); this._animationTimer = null; } }, // fireAction will be called to actually fire each registered animation action _$ratio_ID_earlyFinish:"ratio,ID,earlyFinish", fireAction : function (action, ratio, earlyFinish) { // pass the earlyFinish param on to the action callback. var target = action.target; if (!target || target.destroyed) { return "No valid target. Target may have been destroyed since animation commenced"; } target.fireCallback(action.callback, this._$ratio_ID_earlyFinish, [ratio,action.ID,earlyFinish]); }, // Globally are any animations in progress? isActive : function () { return (this.registry && this.registry.length > 0); }});isc.Canvas.addProperties({ //> @attr canvas.animateTime (number : 300 : IRWA) // Default total duration of animations. Can be overridden by setting animation times for // specific animations, or by passing a <code>duration</code> parameter into the appropriate // animate...() method. // @visibility animation // @group animation // @example animateMove //< animateTime:300, //> @attr canvas.animateAcceleration (AnimationEffect : "smoothEnd" : IRWA) // Default acceleration effect to apply to all animations on this Canvas. // Can be overridden by setting animationAcceleration for specific animations or by passing // an acceleration function directly into the appropriate method. // @visibility animation // @group animation //< animateAcceleration:"smoothEnd", // List of supported animations. // For each of these we need to support the method 'animate[Type]' (like animateMove()). // These method names can also be passed as parameters to finishAnimation() _animations:["rect","fade","scroll","show","hide"] //> @attr canvas.animateMoveTime (number : null : IRWA) // Default time for performing an animated move. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateResizeTime (number : null : IRWA) // Default time for performing an animated resize. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateRectTime (number : null : IRWA) // Default time for performing an animated setRect. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateFadeTime (number : null : IRWA) // Default time for performing an animated fade. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateScrollTime (number : null : IRWA) // Default time for performing an animated scroll. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateShowTime (number : null : IRWA) // Default time for performing an animated show. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateHideTime (number : null : IRWA) // Default time for performing an animated hide. If unset, <code>this.animateTime</code> // will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateMoveAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration effect for performing an animated move. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateResizeAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration function for performing an animated resize. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateRectAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration function for performing an animated move and resize. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateScrollAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration function for performing an animated scroll. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateShowAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration function for performing an animated show. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< //> @attr canvas.animateHideAcceleration (AnimationAcceleration : null : IRWA) // Default acceleration function for performing an animated hide. If unset, // <code>this.animateAcceleration</code> will be used by default instead // @visibility animation // @group animation //< })isc.Canvas.addMethods({ //> @method canvas.registerAnimation (A) // Register some action to fire repeatedly for a specified duration // @param callback (callback) Action to fire repeatedly until the duration expires // @param [duration] (number) time in ms for which the action should be fired // @param [acceleration] (AnimationAcceleration) Acceleration effect to apply to the animation // @return (string) Unique identifier for the registered animation action // @visibility animation_advanced // @group animation //< registerAnimation : function (callback, duration, acceleration) { if (!acceleration) acceleration = this.animationAcceleration; if (!duration) duration = this.animateTime; return isc.Animation.registerAnimation(callback, duration, acceleration, this); }, //> @method canvas.cancelAnimation (A) // Clear some registered animation action // @param ID (string) ID of the animation as returned by canvas.registerAnimation() // @visibility animation_advanced // @group animation //< cancelAnimation : function (ID) { isc.Animation.clearAnimation(ID); }, // ---------------------------------------------------------------------------------------- // Specific animation effects (Higher level API) // ---------------------------------------------------------------------------------------- // getAnimationType() will return the default duration for various animation types // getAnimationAcceleration() will return the default acceleration function used to bias // animation ratios for the appropriate type _animateTimeMap:{}, _animateAccelerationMap:{}, getAnimateTime : function (type) { if (!isc.isA.String(type) || isc.isAn.emptyString(type)) return this.animateTime; // type is something like "move" or "resize" // - default duration specified via this.animateMoveTime if (!this._animateTimeMap[type]) { this._animateTimeMap[type] = "animate" + type.substring(0,1).toUpperCase() + type.substring(1) + "Time"; } return this[this._animateTimeMap[type]] || this.animateTime; }, getAnimateAcceleration : function (type) { if (!isc.isA.String(type) || isc.isAn.emptyString(type)) return this.animateAcceleration; // - default ratio biasing function specified via this.animate[Type]Acceleration if (!this._animateAccelerationMap[type]) { this._animateAccelerationMap[type] = "animate" + type.substring(0,1).toUpperCase() + type.substring(1) + "Acceleration"; } return this[this._animateAccelerationMap[type]] || this.animateAcceleration; }, // _getAnimationIDs() - each time an animation is set up, the ID of the animation action // is stored under this.[type]Animation (so this.rectAnimation, this.fadeAnimation, etc.) // Helper method to retrieve these IDs _animationIDs:{}, _getAnimationID : function (type) { if (!this._animationIDs[type]) { this._animationIDs[type] = type + "Animation"; } return this._animationIDs[type]; }, // _getAnimationMethodName() - the actions fired (repeatedly) for animations are canonically // named as this.fireAnimation[ActionType](). // Helper to cache / retrieve these names _animationMethodNames:{}, _getAnimationMethodName : function (type) { if (!this._animationMethodNames[type]) { this._animationMethodNames[type] = "fireAnimation" + type.substring(0,1).toUpperCase() + type.substring(1); } return this._animationMethodNames[type]; }, // Helper method fired to start an animation. This method allows us to consolidate the // code path to: // - check if a current animation is in process (and finish it if so) // - store out info for use by repeatedly called animation action // - registers the animation to actually start firing // This method requires the following: // - the repeatedly fired action for an animation will be named "this.fireAnimation[AnimationType]" // - the info passed to this method will be stored as "this.[animationType]Info" (so the // action should be prepared to access that object) // - the ID of the registered animation will be stored as "this.[animationType]Animation" // o this ID should be cleared out when the animation completes _animationInfoAttrs:{}, _startAnimation : function (type, info, duration, acceleration) { var ID = this._getAnimationID(type); // If an animation of the same type is already running, finish it before starting this // one. if (this[ID]) this.finishAnimation(type); // Hang onto the info passed in - will be used by the animation action fired if (!this._animationInfoAttrs[type]) // NB: using $ instead of _ prefix to avoid obfuscation problems this._animationInfoAttrs[type] = "$" + type + "AnimationInfo"; this[this._animationInfoAttrs[type]] = info; if (duration == null) duration = this.getAnimateTime(type); if (acceleration == null) acceleration = this.getAnimateAcceleration(type); // Register the animation method to fire for the specified duration var animationId = this[ID] = this.registerAnimation(this[this._getAnimationMethodName(type)], duration, acceleration);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -