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

📄 slider.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
        return true;    },    /**     * Move the associated slider moved to a timeout to try to get around the      * mousedown stealing moz does when I move the slider element between the      * cursor and the background during the mouseup event     * @method moveThumb     * @param {int} x the X coordinate of the click     * @param {int} y the Y coordinate of the click     * @param {boolean} skipAnim don't animate if the move happend onDrag     * @param {boolean} midMove set to true if this is not terminating     * the slider movement     * @private     */    moveThumb: function(x, y, skipAnim, midMove) {        var t = this.thumb;        var self = this;        if (!t.available) {            return;        }        t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y);        var _p = t.getTargetCoord(x, y);        var p = [Math.round(_p.x), Math.round(_p.y)];        this._slideStart();        if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && t._graduated && !skipAnim) {            // this.thumb._animating = true;            this.lock();            // cache the current thumb pos            this.curCoord = YAHOO.util.Dom.getXY(this.thumb.getEl());            this.curCoord = [Math.round(this.curCoord[0]), Math.round(this.curCoord[1])];            setTimeout( function() { self.moveOneTick(p); }, this.tickPause );        } else if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && !skipAnim) {            // this.thumb._animating = true;            this.lock();            var oAnim = new YAHOO.util.Motion(                     t.id, { points: { to: p } },                     this.animationDuration,                     YAHOO.util.Easing.easeOut );            oAnim.onComplete.subscribe( function() {                                         self.endMove();                 } );            oAnim.animate();        } else {            t.setDragElPos(x, y);            // this.fireEvents();            if (!midMove) {                this.endMove();            }        }    },    _slideStart: function() {        if (!this._sliding) {            if (!this._silent) {                this.onSlideStart();                this.fireEvent("slideStart");            }            this._sliding = true;        }    },    _slideEnd: function() {        if (this._sliding && this.moveComplete) {            // Reset state before firing slideEnd            var silent = this._silent;            this._sliding = false;            this._silent = false;            this.moveComplete = false;            if (!silent) {                this.onSlideEnd();                this.fireEvent("slideEnd");            }        }    },    /**     * Move the slider one tick mark towards its final coordinate.  Used     * for the animation when tick marks are defined     * @method moveOneTick     * @param {int[]} the destination coordinate     * @private     */    moveOneTick: function(finalCoord) {        var t = this.thumb, tmp;        // redundant call to getXY since we set the position most of time prior         // to getting here.  Moved to this.curCoord        //var curCoord = YAHOO.util.Dom.getXY(t.getEl());        // alignElWithMouse caches position in lastPageX, lastPageY .. doesn't work        //var curCoord = [this.lastPageX, this.lastPageY];        // var thresh = Math.min(t.tickSize + (Math.floor(t.tickSize/2)), 10);        // var thresh = 10;        // var thresh = t.tickSize + (Math.floor(t.tickSize/2));        var nextCoord = null,            tmpX, tmpY;        if (t._isRegion) {            nextCoord = this._getNextX(this.curCoord, finalCoord);            tmpX = (nextCoord !== null) ? nextCoord[0] : this.curCoord[0];            nextCoord = this._getNextY(this.curCoord, finalCoord);            tmpY = (nextCoord !== null) ? nextCoord[1] : this.curCoord[1];            nextCoord = tmpX !== this.curCoord[0] || tmpY !== this.curCoord[1] ?                [ tmpX, tmpY ] : null;        } else if (t._isHoriz) {            nextCoord = this._getNextX(this.curCoord, finalCoord);        } else {            nextCoord = this._getNextY(this.curCoord, finalCoord);        }        if (nextCoord) {            // cache the position            this.curCoord = nextCoord;            // move to the next coord            // YAHOO.util.Dom.setXY(t.getEl(), nextCoord);            // var el = t.getEl();            // YAHOO.util.Dom.setStyle(el, "left", (nextCoord[0] + this.thumb.deltaSetXY[0]) + "px");            // YAHOO.util.Dom.setStyle(el, "top",  (nextCoord[1] + this.thumb.deltaSetXY[1]) + "px");            this.thumb.alignElWithMouse(t.getEl(), nextCoord[0] + this.thumbCenterPoint.x, nextCoord[1] + this.thumbCenterPoint.y);                        // check if we are in the final position, if not make a recursive call            if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) {                var self = this;                setTimeout(function() { self.moveOneTick(finalCoord); },                         this.tickPause);            } else {                this.endMove();            }        } else {            this.endMove();        }        //this.tickPause = Math.round(this.tickPause/2);    },    /**     * Returns the next X tick value based on the current coord and the target coord.     * @method _getNextX     * @private     */    _getNextX: function(curCoord, finalCoord) {        var t = this.thumb;        var thresh;        var tmp = [];        var nextCoord = null;        if (curCoord[0] > finalCoord[0]) {            thresh = t.tickSize - this.thumbCenterPoint.x;            tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] );            nextCoord = [tmp.x, tmp.y];        } else if (curCoord[0] < finalCoord[0]) {            thresh = t.tickSize + this.thumbCenterPoint.x;            tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] );            nextCoord = [tmp.x, tmp.y];        } else {            // equal, do nothing        }        return nextCoord;    },    /**     * Returns the next Y tick value based on the current coord and the target coord.     * @method _getNextY     * @private     */    _getNextY: function(curCoord, finalCoord) {        var t = this.thumb;        var thresh;        var tmp = [];        var nextCoord = null;        if (curCoord[1] > finalCoord[1]) {            thresh = t.tickSize - this.thumbCenterPoint.y;            tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh );            nextCoord = [tmp.x, tmp.y];        } else if (curCoord[1] < finalCoord[1]) {            thresh = t.tickSize + this.thumbCenterPoint.y;            tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh );            nextCoord = [tmp.x, tmp.y];        } else {            // equal, do nothing        }        return nextCoord;    },    /**     * Resets the constraints before moving the thumb.     * @method b4MouseDown     * @private     */    b4MouseDown: function(e) {        if (!this.backgroundEnabled) {            return false;        }        this.thumb.autoOffset();        //this.thumb.resetConstraints();        this.resetThumbConstraints();    },    /**     * Handles the mousedown event for the slider background     * @method onMouseDown     * @private     */    onMouseDown: function(e) {        // this.resetConstraints(true);        // this.thumb.resetConstraints(true);        if (!this.backgroundEnabled || this.isLocked()) {            return false;        }        var x = YAHOO.util.Event.getPageX(e);        var y = YAHOO.util.Event.getPageY(e);        this.focus();        this.moveThumb(x, y);    },    /**     * Handles the onDrag event for the slider background     * @method onDrag     * @private     */    onDrag: function(e) {        if (this.backgroundEnabled && !this.isLocked()) {            var x = YAHOO.util.Event.getPageX(e);            var y = YAHOO.util.Event.getPageY(e);            this.moveThumb(x, y, true, true);            this.fireEvents();        }    },    /**     * Fired when the slider movement ends     * @method endMove     * @private     */    endMove: function () {        // this._animating = false;        this.unlock();        this.moveComplete = true;        this.fireEvents();    },    /**     * Resets the X and Y contraints for the thumb.  Used in lieu of the thumb     * instance's inherited resetConstraints because some logic was not     * applicable.     * @method resetThumbConstraints     * @protected     */    resetThumbConstraints: function () {        var t = this.thumb;        t.setXConstraint(t.leftConstraint, t.rightConstraint, t.xTickSize);        t.setYConstraint(t.topConstraint, t.bottomConstraint, t.xTickSize);    },    /**     * Fires the change event if the value has been changed.  Ignored if we are in     * the middle of an animation as the event will fire when the animation is     * complete     * @method fireEvents     * @param {boolean} thumbEvent set to true if this event is fired from an event     *                  that occurred on the thumb.  If it is, the state of the     *                  thumb dd object should be correct.  Otherwise, the event     *                  originated on the background, so the thumb state needs to     *                  be refreshed before proceeding.     * @private     */    fireEvents: function (thumbEvent) {        var t = this.thumb;        if (!thumbEvent) {            t.cachePosition();        }        if (! this.isLocked()) {            if (t._isRegion) {                var newX = t.getXValue();                var newY = t.getYValue();                if (newX != this.previousX || newY != this.previousY) {                    if (!this._silent) {                        this.onChange(newX, newY);                        this.fireEvent("change", { x: newX, y: newY });                    }                }                this.previousX = newX;                this.previousY = newY;            } else {                var newVal = t.getValue();                if (newVal != this.previousVal) {                    if (!this._silent) {                        this.onChange( newVal );                        this.fireEvent("change", newVal);                    }                }                this.previousVal = newVal;            }            this._slideEnd();        }    },    /**     * Slider toString     * @method toString     * @return {string} string representation of the instance     */    toString: function () {         return ("Slider (" + this.type +") " + this.id);    }});YAHOO.augment(YAHOO.widget.Slider, YAHOO.util.EventProvider);/** * A drag and drop implementation to be used as the thumb of a slider. * @class SliderThumb * @extends YAHOO.util.DD * @constructor * @param {String} id the id of the slider html element * @param {String} sGroup the group of related DragDrop items * @param {int} iLeft the number of pixels the element can move left * @param {int} iRight the number of pixels the element can move right * @param {int} iUp the number of pixels the element can move up * @param {int} iDown the number of pixels the element can move down * @param {int} iTickSize optional parameter for specifying that the element  * should move a certain number pixels at a time. */YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) {    if (id) {        //this.init(id, sGroup);        YAHOO.widget.SliderThumb.superclass.constructor.call(this, id, sGroup);        /**         * The id of the thumbs parent HTML element (the slider background          * element).         * @property parentElId         * @type string         */        this.parentElId = sGroup;    }    //this.removeInvalidHandleType("A");    /**     * Overrides the isTarget property in YAHOO.util.DragDrop     * @property isTarget

⌨️ 快捷键说明

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