首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js中面向对象写法解决思路

2012-09-07 
js中面向对象写法JScript codefunction createPicMove(a, b, c) { var h function (k, n, m, l) {this._

js中面向对象写法

JScript code
function createPicMove(a, b, c) { var h = function (k, n, m, l) {        this._slider = g(n);        this._container = g(k);        this._timer = null;        this._count = Math.abs(m);        this._target = 0;        this._t = this._b = this._c = 0;        this.Index = 0;        this.SetOptions(l);        this.Auto = !!this.options.Auto;        this.Duration = Math.abs(this.options.Duration);        this.Time = Math.abs(this.options.Time);        this.Pause = Math.abs(this.options.Pause);        this.Tween = this.options.Tween;        this.onStart = this.options.onStart;        this.onFinish = this.options.onFinish;        var j = !!this.options.Vertical;        this._css = j ? "top" : "left";        var o = f(this._container).position;        o == "relative" || o == "absolute" || (this._container.style.position = "relative");        this._container.style.overflow = "hidden";        this._slider.style.position = "absolute";        this.Change = this.options.Change ? this.options.Change : this._slider[j ? "offsetHeight" : "offsetWidth"] / this._count    };    h.prototype = {        SetOptions: function (j) {            this.options = {                Vertical: true,                Auto: true,                Change: 0,                Duration: 50,                Time: 10,                Pause: 4000,                onStart: function () { },                onFinish: function () { },                Tween: e.Quart.easeOut            };            d(this.options, j || {})        },        Run: function (j) {            j == undefined && (j = this.Index);            j < 0 && (j = this._count - 1) || j >= this._count && (j = 0);            this._target = -Math.abs(this.Change) * (this.Index = j);            this._t = 0;            this._b = parseInt(f(this._slider)[this.options.Vertical ? "top" : "left"]);            this._c = this._target - this._b;            this.onStart();            this.Move()        },        Move: function () {            clearTimeout(this._timer);            if (this._c && this._t < this.Duration) {                this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));                this._timer = setTimeout(i(this, this.Move), this.Time)            } else {                this.MoveTo(this._target);                this.Auto && (this._timer = setTimeout(i(this, this.Next), this.Pause))            }        },        MoveTo: function (j) {            this._slider.style[this._css] = j + "px"        },        Next: function () {            this.Run(++this.Index)        },        Previous: function () {            this.Run(--this.Index)        },        Stop: function () {            clearTimeout(this._timer);            this.MoveTo(this._target)        }    };    return new h(a, b, c, {        Vertical: false    })}

本人菜鸟,想问下各位,如何触发 Next 、Previous函数。
先谢谢

[解决办法]
JScript code
  <script type="text/javascript">        var picMove = createPicMove("参数列表");        picMove.Next();        picMove.Previous();      </script>
[解决办法]
创建实例然后通过实例调用
JScript code
var o=new createPicMove(/*a,b,c参数的值*/)o.Next();o.Previouse()
[解决办法]
你这个是类似于工厂函数
createPicMove().Previous()就可以调用
HTML code
function aa(){                var o = function(){                    this.name = "深蓝";                }                o.prototype = {                    previous : function(){                        alert(this.name)                    }                }                return new o();            }                        var obj = aa();            obj.previous() 

热点排行