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

📄 slider.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
     * @private     */    this.isTarget = false;    /**     * The tick size for this slider     * @property tickSize     * @type int     * @private     */    this.tickSize = iTickSize;    /**     * Informs the drag and drop util that the offsets should remain when     * resetting the constraints.  This preserves the slider value when     * the constraints are reset     * @property maintainOffset     * @type boolean     * @private     */    this.maintainOffset = true;    this.initSlider(iLeft, iRight, iUp, iDown, iTickSize);    /**     * Turns off the autoscroll feature in drag and drop     * @property scroll     * @private     */    this.scroll = false;}; YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, {    /**     * The (X and Y) difference between the thumb location and its parent      * (the slider background) when the control is instantiated.     * @property startOffset     * @type [int, int]     */    startOffset: null,    /**     * Override the default setting of dragOnly to true.     * @property dragOnly     * @type boolean     * @default true     */    dragOnly : true,    /**     * Flag used to figure out if this is a horizontal or vertical slider     * @property _isHoriz     * @type boolean     * @private     */    _isHoriz: false,    /**     * Cache the last value so we can check for change     * @property _prevVal     * @type int     * @private     */    _prevVal: 0,    /**     * The slider is _graduated if there is a tick interval defined     * @property _graduated     * @type boolean     * @private     */    _graduated: false,    /**     * Returns the difference between the location of the thumb and its parent.     * @method getOffsetFromParent     * @param {[int, int]} parentPos Optionally accepts the position of the parent     * @type [int, int]     */    getOffsetFromParent0: function(parentPos) {        var myPos = YAHOO.util.Dom.getXY(this.getEl());        var ppos  = parentPos || YAHOO.util.Dom.getXY(this.parentElId);        return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];    },    getOffsetFromParent: function(parentPos) {        var el = this.getEl(), newOffset;        if (!this.deltaOffset) {            var myPos = YAHOO.util.Dom.getXY(el);            var ppos  = parentPos || YAHOO.util.Dom.getXY(this.parentElId);            newOffset = [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];            var l = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );            var t = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );            var deltaX = l - newOffset[0];            var deltaY = t - newOffset[1];            if (isNaN(deltaX) || isNaN(deltaY)) {            } else {                this.deltaOffset = [deltaX, deltaY];            }        } else {            var newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );            var newTop  = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );            newOffset  = [newLeft + this.deltaOffset[0], newTop + this.deltaOffset[1]];        }        return newOffset;        //return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];    },    /**     * Set up the slider, must be called in the constructor of all subclasses     * @method initSlider     * @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 the width of the tick interval.     */    initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) {        //document these.  new for 0.12.1        this.initLeft = iLeft;        this.initRight = iRight;        this.initUp = iUp;        this.initDown = iDown;        this.setXConstraint(iLeft, iRight, iTickSize);        this.setYConstraint(iUp, iDown, iTickSize);        if (iTickSize && iTickSize > 1) {            this._graduated = true;        }        this._isHoriz  = (iLeft || iRight);         this._isVert   = (iUp   || iDown);        this._isRegion = (this._isHoriz && this._isVert);     },    /**     * Clear's the slider's ticks     * @method clearTicks     */    clearTicks: function () {        YAHOO.widget.SliderThumb.superclass.clearTicks.call(this);        this.tickSize = 0;        this._graduated = false;    },    /**     * Gets the current offset from the element's start position in     * pixels.     * @method getValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved from the start position.     */    getValue: function () {        return (this._isHoriz) ? this.getXValue() : this.getYValue();    },    /**     * Gets the current X offset from the element's start position in     * pixels.     * @method getXValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved horizontally from the start position.     */    getXValue: function () {        if (!this.available) {             return 0;         }        var newOffset = this.getOffsetFromParent();        if (YAHOO.lang.isNumber(newOffset[0])) {            this.lastOffset = newOffset;            return (newOffset[0] - this.startOffset[0]);        } else {            return (this.lastOffset[0] - this.startOffset[0]);        }    },    /**     * Gets the current Y offset from the element's start position in     * pixels.     * @method getYValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved vertically from the start position.     */    getYValue: function () {        if (!this.available) {             return 0;         }        var newOffset = this.getOffsetFromParent();        if (YAHOO.lang.isNumber(newOffset[1])) {            this.lastOffset = newOffset;            return (newOffset[1] - this.startOffset[1]);        } else {            return (this.lastOffset[1] - this.startOffset[1]);        }    },    /**     * Thumb toString     * @method toString     * @return {string} string representation of the instance     */    toString: function () {         return "SliderThumb " + this.id;    },    /**     * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider     * instance it belongs to.     * @method onChange     * @private     */    onChange: function (x, y) {     }});/** * A slider with two thumbs, one that represents the min value and  * the other the max.  Actually a composition of two sliders, both with * the same background.  The constraints for each slider are adjusted * dynamically so that the min value of the max slider is equal or greater * to the current value of the min slider, and the max value of the min * slider is the current value of the max slider. * Constructor assumes both thumbs are positioned absolutely at the 0 mark on * the background. * * @namespace YAHOO.widget * @class DualSlider * @uses YAHOO.util.EventProvider * @constructor * @param {Slider} minSlider The Slider instance used for the min value thumb * @param {Slider} maxSlider The Slider instance used for the max value thumb * @param {int}    range The number of pixels the thumbs may move within * @param {Array}  initVals (optional) [min,max] Initial thumb placement */YAHOO.widget.DualSlider = function(minSlider, maxSlider, range, initVals) {    var self = this,        lang = YAHOO.lang;    /**     * A slider instance that keeps track of the lower value of the range.     * <strong>read only</strong>     * @property minSlider     * @type Slider     */    this.minSlider = minSlider;    /**     * A slider instance that keeps track of the upper value of the range.     * <strong>read only</strong>     * @property maxSlider     * @type Slider     */    this.maxSlider = maxSlider;    /**     * The currently active slider (min or max). <strong>read only</strong>     * @property activeSlider     * @type Slider     */    this.activeSlider = minSlider;    /**     * Is the DualSlider oriented horizontally or vertically?     * <strong>read only</strong>     * @property isHoriz     * @type boolean     */    this.isHoriz = minSlider.thumb._isHoriz;    // Validate initial values    initVals = YAHOO.lang.isArray(initVals) ? initVals : [0,range];    initVals[0] = Math.min(Math.max(parseInt(initVals[0],10)|0,0),range);    initVals[1] = Math.max(Math.min(parseInt(initVals[1],10)|0,range),0);    // Swap initVals if min > max    if (initVals[0] > initVals[1]) {        initVals.splice(0,2,initVals[1],initVals[0]);    }    var ready = { min : false, max : false };    this.minSlider.thumb.onAvailable = function () {        minSlider.setStartSliderState();        ready.min = true;        if (ready.max) {            minSlider.setValue(initVals[0],true,true,true);            maxSlider.setValue(initVals[1],true,true,true);            self.updateValue(true);            self.fireEvent('ready',self);        }    };    this.maxSlider.thumb.onAvailable = function () {        maxSlider.setStartSliderState();        ready.max = true;        if (ready.min) {            minSlider.setValue(initVals[0],true,true,true);            maxSlider.setValue(initVals[1],true,true,true);            self.updateValue(true);            self.fireEvent('ready',self);        }    };    // dispatch mousedowns to the active slider    minSlider.onMouseDown = function(e) {        return self._handleMouseDown(e);    };    // we can safely ignore a mousedown on one of the sliders since    // they share a background    maxSlider.onMouseDown = function(e) {         if (self.minSlider.isLocked() && !self.minSlider._sliding) {            return self._handleMouseDown(e);        } else {            YAHOO.util.Event.stopEvent(e);             return false;        }    };    // Fix the drag behavior so that only the active slider    // follows the drag    minSlider.onDrag =    maxSlider.onDrag = function(e) {        self._handleDrag(e);    };    // The core events for each slider are handled so we can expose a single    // event for when the event happens on either slider    minSlider.subscribe("change", this._handleMinChange, minSlider, this);    minSlider.subscribe("slideStart", this._handleSlideStart, minSlider, this);    minSlider.subscribe("slideEnd", this._handleSlideEnd, minSlider, this);    maxSlider.subscribe("change", this._handleMaxChange, maxSlider, this);    maxSlider.subscribe("slideStart", this._handleSlideStart, maxSlider, this);    maxSlider.subscribe("slideEnd", this._handleSlideEnd, maxSlider, this);    /**     * Event that fires when the slider is finished setting up     * @event ready     * @param {DualSlider} dualslider the DualSlider instance     */    this.createEvent("ready", this);    /**     * Event that fires when either the min or max value changes     * @event change     * @param {DualSlider} dualslider the DualSlider instance     */    this.createEvent("change", this);    /**     * Event that fires when one of the thumbs begins to move     * @event slideStart     * @param {Slider} activeSlider the moving slider     */    this.createEvent("slideStart", this);    /**     * Event that fires when one of the thumbs finishes moving     * @event slideEnd     * @param {Slider} activeSlider the moving slider     */    this.createEvent("slideEnd", this);};YAHOO.widget.DualSlider.prototype = {    /**

⌨️ 快捷键说明

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