var IMGConvert = function (imgId, textId) { var wc = this; this.constructor = arguments.callee; this.step = 4; this.time = 5000; this.cstep = 20; this.imgElement = document.getElementById(imgId); this.textElement = document.getElementById(textId); //this.infoElement = document.getElementById(infoId); this.timer = this.ctimer = this.i = this.j = 0; this.each(this.anchorLists = [], this.imgElement.getElementsByTagName('a'), function (a, b) { a.push(b); b.style.display = 'none'; }); this.each(this.textLists = [], this.textElement.getElementsByTagName('li'), function (a, b, i) { a.push(b); b.onmouseover = function () { if( wc.i == i ) { return; } with (wc.reItem(wc.i, wc.textLists).style) { backgroundColor = '#666', color = '#FFF'; } //wc.convert(i - 1); wc.convert(i); }; }); if (this.anchorLists.length < 2) return; this.init(); }; IMGConvert.prototype = { each : function (a, b, f) { for (var i = 0, l = b.length ; i < l ; i ++) f(a, b[i], i); } , init : function () { var wc = this; this.anchorLists[0].style.display = 'block'; this.setText(); this.timer = window.setTimeout(function () { wc.convert(); }, this.time); } , reItem : function (i, a) { //获得元素 return i >= a.length ? a[0] : i < 0 ? a[a.length - 1] : a[i]; } , setText : function () { //设置字 with (this.reItem(this.j, this.textLists).style) { backgroundColor = '#666', color = '#FFF'; } with (this.textLists[this.i].style) { backgroundColor = '#a50c0d', color = '#fff'; } //this.infoElement.innerHTML = this.anchorLists[this.i].getElementsByTagName('img')[0].getAttribute('alt').replace(//ig, '>'); } , convert : function (n) { //切换 var wc = this, i = 100, n = 'undefined' == typeof n ? (this.i + 1) : n; this.clear(1); var tmp_j = this.i; this.i = n >= this.anchorLists.length ? 0 : n < 0 ? this.anchorLists.length - 1 : n; this.j = tmp_j; var a = this.reItem(this.j, this.anchorLists), b = this.reItem(this.i, this.anchorLists); //this.clear(1); this.time = this.i == 0 ? 10000 : 5000; this.setText(); a.style.zIndex = 2, b.style.zIndex = 1; a.style.display = b.style.display = 'block'; a.style.filter = b.style.filter = 'alpha(opacity=100)'; a.style.opacity = b.style.opacity = 1.0; this.timer = window.setInterval(function () { if (i < 0) { wc.clear(); wc.ctimer = window.setTimeout(function () { wc.convert(); }, wc.time); } a.style.filter = 'alpha(opacity=' + i + ')'; a.style.opacity = i / 100; i -= wc.step; }, this.cstep); } , clear : function (b) { //清理 this.timer && (window.clearInterval(this.timer), (this.timer = 0)); this.ctimer && (window.clearTimeout(this.ctimer), (this.ctimer = 0)); this.reItem(this.j, this.anchorLists).style.display = 'none'; b && (this.reItem(this.i, this.anchorLists).style.display = 'none'); } };