ColorTrans部分:
var ColorTrans = function(obj, options){ this._obj = $(obj); this._timer = null;//定時器 this._index = 0;//索引 this._colors = [];//顏色集合 this._grads = new ColorGrads(); this.SetOptions(options); this.Speed = Math.abs(this.options.Speed); this.CssColor = this.options.CssColor; this._startColor = this.options.StartColor || CurrentStyle(this._obj)[this.CssColor]; this._endColor = this.options.EndColor; this._step = Math.abs(this.options.Step); this.Reset(); this.SetColor(); }; ColorTrans.prototype = { //設置默認屬性 SetOptions: function(options) { this.options = {//默認值 StartColor: "",//開始顏色 EndColor: "#000",//結束顏色 Step: 20,//漸變級數(shù) Speed: 20,//漸變速度 CssColor: "color"http://設置屬性(Scripting屬性) }; Extend(this.options, options || {}); }, //重設顏色集合 Reset: function(color) { //修改顏色后必須重新獲取顏色集合 color = Extend({ StartColor: this._startColor, EndColor: this._endColor, Step: this._step }, color || {}); //設置屬性 this._grads.StartColor = this._startColor = color.StartColor; this._grads.EndColor = this._endColor = color.EndColor; this._grads.Step = this._step = color.Step; //獲取顏色集合 this._colors = this._grads.Create(); this._index = 0; }, //顏色漸入 FadeIn: function() { this.Stop(); this._index++; this.SetColor(); if(this._index < this._colors.length - 1){ this._timer = setTimeout(Bind(this, this.FadeIn), this.Speed); } }, //顏色漸出 FadeOut: function() { this.Stop(); this._index--; this.SetColor(); if(this._index > 0){ this._timer = setTimeout(Bind(this, this.FadeOut), this.Speed); } }, //顏色設置 SetColor: function() { var color = this._colors[Math.min(Math.max(0, this._index), this._colors.length - 1)]; this._obj.style[this.CssColor] = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")"; }, //停止 Stop: function() { clearTimeout(this._timer); } };
下載完整實例
原文:http://www.cnblogs.com/cloudgamer/
本文鏈接:http://www.95time.cn/tech/web/2009/6735.asp
出處:cloudgamer
責任編輯:bluehearts
上一頁 JavaScript 顏色梯度和漸變效果 [4] 下一頁
◎進入論壇網(wǎng)頁制作、WEB標準化版塊參加討論,我還想發(fā)表評論。
|