⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animation.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
        if (this.logIsInfoEnabled("animation")) {            this.logInfo("starting animation " + animationId + " of type: " + type +                         ", duration: " + duration +                          ", acceleration: " + this.echoLeaf(acceleration),                         "animation");        }               return animationId;    },        // helper method to fire the final callback at the end of an animation.        _fireAnimationCompletionCallback : function (callback, earlyFinish, synchronous) {            if (!callback) return;        var widget = this;        var fireCallback = function () {            widget.fireCallback(callback, "earlyFinish", [earlyFinish]);        }                                      if (earlyFinish || synchronous) {            fireCallback();        } else {                 isc.Timer.setTimeout(fireCallback, 0);        }    },        //> @method canvas.finishAnimation()    // Forces a running animation (animated move / resize, etc.) to instantly complete - jumping    // to its finished state, and firing its callback, and passing the 'earlyFinish' parameter    // to the callback.    // @param [type] (string) animation type name ("move", "resize", etc). If not passed just    //                        finish all animations    // @visibility internal    // @group animation    //<        finishAnimation : function (type) {               // if type is null finish animations of all types        if (type == null) {            for (var i = 0 ; i < this._animations.length; i++) {                this.finishAnimation(this._animations[i]);            }            return;        }                // Every animation stores it's currently registered animation as this.[type]Animation        // If we're not currently performing an animation of this type no need to proceed        var ID = this._getAnimationID(type);        if (!this[ID]) return;                // Call 'finishAnimation' directly on the Animation class. This will cancel further        // animations and fire the animation action with a ratio of 1, passing in the         // 'earlyFinish' parameter.        if (this.logIsInfoEnabled("animation")) {            this.logInfo("manual finish for animations: " + this.echoAll(this[ID]) +                          (this.logIsDebugEnabled("animation") ? this.getStackTrace() : ""),                          "animation");        }        isc.Animation.finishAnimation(this[ID]);    },        // --------------------------------    // Developer visible APIS:        //> @method canvas.animateMove()    // Animate a reposition of this canvas from its current position to the specified position    // @param left (number) new left position (or null for unchanged)    // @param top (number) new top position (or null for unchanged)    // @param [callback] (callback) When the move completes this callback will be fired. Single    //                              'earlyFinish' parameter will be passed if the animation was    //                              cut short by a call to finishAnimation    // @param [duration] (number) Duration in ms of the animated move     // @param [acceleration] (AnimationAcceleration) Optional acceleration effect to bias the ratios    // @visibility animation    // @group animation    // @example animateMove    //<        _$move:"move",    animateMove : function (left, top, callback, duration, acceleration) {        return this.animateRect(left, top, null, null, callback, duration,                                 acceleration, this._$move);    },    fireAnimationMove : function (ratio, ID, earlyFinish) {        // pass along the additional "type" parameter        return this.fireAnimationRect(ratio, ID, earlyFinish, this._$move);    },        //> @method canvas.animateResize()    // Animate a resize of this canvas from its current size to the specified size    // @param width (number) new width (or null for unchanged)    // @param height (number) new height (or null for unchanged)    // @param [callback] (callback) When the resize completes this callback will be fired. Single    //                              'earlyFinish' parameter will be passed if the animation was    //                              cut short by a call to finishAnimation    // @param [duration] (number) Duration in ms of the animated resize     // @param [acceleration] (AnimationAcceleration) Optional acceleration effect to apply to the resize    // @visibility animation    // @group animation    // @example animateResize    //<    _$resize:"resize",    animateResize : function (width, height, callback, duration, acceleration) {        return this.animateRect(null, null, width, height, callback, duration, acceleration,                                     this._$resize);    },    fireAnimationResize : function (ratio, ID, earlyFinish) {        // pass along the additional 'type' parameter        return this.fireAnimationRect(ratio, ID, earlyFinish, this._$resize);    },        //> @method canvas.animateRect()    // Animate a reposition / resize of this canvas from its current size and postion.    // @param left (number) new left position (or null for unchanged)    // @param top (number) new top position (or null for unchanged)    // @param width (number) new width (or null for unchanged)    // @param height (number) new height (or null for unchanged)    // @param [callback] (callback) When the setRect completes this callback will be fired. Single    //                              'earlyFinish' parameter will be passed if the animation was    //                              cut short by a call to finishAnimation    // @param [duration] (number) Duration in ms of the animated setRect     // @param [acceleration] (AnimationAcceleration) Optional acceleration effect to apply to the animation    // @visibility animation    // @group animation    // @example animateZoom    //<    // Additional type parameter allows us to pick up default durations for animated     // move / resizes, which fall through to this method        _$rect:"rect",    animateRect : function (left, top, width, height, callback, duration, acceleration, type) {        if (type == null) {            type = this._$rect;            // when starting a new "rect" animation, we need to finish any currently running            // "resize", "move", or "rect" animations.  "rect" animations will automatically be            // killed by starting a new "rect" animation (in _startAnimation()), but we have to            // kill "resize" or "move" animations here directly            if (this.resizeAnimation != null) this.finishAnimation(this._$resize);            if (this.moveAnimation != null) this.finishAnimation(this._$move);        }                // This info object will be available to the repeatedly fired animation action as        // this.$rectAnimationInfo        var info = {_fromRect:this.getRect(), _left:left, _top:top, _width:width, _height:height,                    _callback:callback};                          // call this._startAnimation() to handle actually setting up the animation.        return this._startAnimation(type, info, duration, acceleration);    },        // fireAnimationRect() - fired repeatedly on a timer as the setRect animation proceeds    // when ratio == 1 the animation is complete    // Note: we rely on this naming scheme "fireAnimation[AnimationType]"     // in '_startAnimation()' / 'finishAnimation()'    fireAnimationRect : function (ratio, ID, earlyFinish, type) {                var info = (type == this._$resize ? this.$resizeAnimationInfo :                     (type == this._$move ? this.$moveAnimationInfo : this.$rectAnimationInfo)),            fromRect = info._fromRect,            toLeft = info._left, toTop = info._top,             toWidth = info._width, toHeight = info._height,                        left =                   toLeft != null ? this._getRatioTargetValue(fromRect[0], toLeft, ratio) : null,            top =                 toTop != null ? this._getRatioTargetValue(fromRect[1], toTop, ratio) : null;        // hueristic for smooth enlarge/shrink and similar animations: during eg a shrink from        // all 4 corners, we are increasing left while shrinking width.  In order for centered        // content within the rect to stay at a stable position, width must shrink by exactly        // double what left changes by.  This won't happen if we do separate         // (ratio * difference) calculations, no matter if we use Math.round,ceil,or floor.        // Instead, if width and left or height and top are both changing and are an even        // multiple of each other, use a multiple of left's delta for width instead of        // calculating the width delta separately (likewise for top/height).        var width, height;        if (toWidth != null && left != null && (toLeft - fromRect[0] != 0)) {            var sideRatio = (toWidth - fromRect[2]) / (toLeft - fromRect[0]);            if (Math.floor(sideRatio) == sideRatio) {                //this.logWarn("using ratio: " + sideRatio +                 //             ", fromRect: " + fromRect +                 //             ", toLeft,toWidth: " + [toLeft,toWidth] +                //             ", on delta: " + (left - fromRect[0]));                width = fromRect[2] + (sideRatio * (left - fromRect[0]))            }        }        if (toHeight != null && top != null && (toTop - fromRect[1] != 0)) {            var sideRatio = (toHeight - fromRect[3]) / (toTop - fromRect[1]);            if (Math.floor(sideRatio) == sideRatio) {                height = fromRect[3] + (sideRatio * (top - fromRect[1]))            }        }        if (width == null && toWidth != null) {            width = this._getRatioTargetValue(fromRect[2], toWidth, ratio);        }        if (height == null && toHeight != null) {            height = this._getRatioTargetValue(fromRect[3], toHeight, ratio);        }              if (ratio == 1) {               if (type == this._$resize) {                delete this.$resizeAnimationInfo;                delete this.resizeAnimation            } else if (type == this._$move) {                delete this.$moveAnimationInfo;                delete this.moveAnimation            } else {                delete this.$rectAnimationInfo;                delete this.rectAnimation            }        }        // Pass in the additional 'animating' param.        // - avoids setRect from relaying out children        // - notifies it that this is not an external setRect call in the middle of an        //   animation.                //this.logWarn("ratio: " + ratio + ", animateRect: " + [left,top,width,height]);        this.setRect(left, top, width, height, (ratio < 1));                if (this.isDirty()) this.redraw("animated resize");        if (ratio == 1) {            this._fireAnimationCompletionCallback(info._callback, earlyFinish);        }    },        // A very common pattern in our animations is to step incrementally from one value to     // another.      _getRatioTargetValue : function (from, to, ratio) {        // Common thing - a null 'to' indicates no change        if (to == null) return from;        return (from + Math.floor(ratio * (to - from)));    },        //> @method canvas.animateFade()    // Animate a change in opacity from the widget's current opacity to the specified opacity.    // @param opacity (number) desired final opacity    // @param [callback] (callback) When the fade completes this callback will be fired. Single    //                              'earlyFinish' parameter will be passed if the animation was    //                              cut short by a call to finishAnimation    // @param [duration] (number) Duration in ms of the animated fade     // @param [acceleration] (AnimationAcceleration) Optional animation acceleration to bias the ratios    // @visibility animation    // @group animation    // @example animateFade    //<    animateFade : function (opacity, callback, duration, acceleration) {        if (this.visibility == isc.Canvas.HIDDEN) {            this.setOpacity(0);            this.show();        }        // opacity of 'null' implies default - 100%        if (opacity == null) opacity = 100;                var info = {_fromOpacity:this.opacity != null ? this.opacity : 100,                    _toOpacity:opacity, _callback:callback};        return this._startAnimation("fade", info, duration, acceleration)    },        // fireAnimationFade() - fired repeatedly to perform an animation fade.    fireAnimationFade : function (ratio, ID, earlyFinish) {        var info = this.$fadeAnimationInfo,            fromOpacity = info._fromOpacity,            toOpacity = info._toOpacity;        var opacity = this._getRatioTargetValue(fromOpacity, toOpacity, ratio);                if (isc.Browser.isIE && opacity > 0 && !info._toggledVis) {            var styleHandle = this.getStyleHandle();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -