<script language="javascript">
var oInterval, oTime, oRotator = new Object();
function Rotator(_container, _width, _height, _array, _delay) {
this.author = '51JS.COM-ZMM';
this.version = 'Rotator 1.0';
this.container = _container;
this.width = _width;
this.height = _height;
this.box = (function(_container, _width, _height) {
var _box = document.createElement('DIV');
_box.id = 'RotatorBox';
_box.align = 'center';
_box.style.width = _width;
_box.style.height = _height;
_box.style.border = '1px solid menu';
_box.style.overflow = 'hidden';
return _box;
})(this.container, this.width, this.height);
this.container.appendChild(this.box);
this.sAmount = 0;
this.drawRotator = function(_array, _delay) {
this.delay = _delay;
var _bool = (_array.length == 3);
_bool = _bool & (_array[0].length == _array[1].length);
_bool = _bool & (_array[0].length == _array[2].length);
_bool = _bool & (_array[1].length == _array[2].length);
if (_bool) {
this.itemArr = [];
this.panel = (function(_width, _height, _array) {
var _panel = document.createElement('DIV');
_panel.style.position = 'absolute';
_panel.style.top = '0px';
_panel.style.left = '0px';
return _panel;
})(this.width, this.height, _array);
for (var i=0; i<_array[0].length; i++) {
var _html = new String();
_html += '<table ';
_html += 'width="' + _width + '" height="' + _height + '" ';
_html += 'align="center" valign="middle" ';
_html += 'cellpadding="0" cellspacing="0">';
_html += '<tr><td align="center">';
_html += '<a href="' + _array[0][i] + '">';
_html += '<img src="' + _array[1][i] + '" alt="' + _array[2][i] + '" border="0" ';
_html += 'onmouseover="window.clearInterval(oInterval);" onmouseout="oInterval = window.setInterval(\'oRotator.doScroll()\', ' + this.delay + ');">';
_html += '</a></td></tr>';
_html += '</table>';
this.itemArr[this.itemArr.length] = _html;
}
this.box.appendChild(this.panel);
this.setPanelContent();
} else {
window.alert('arguments error!');
}
}
this.setPanelContent = function() {
this.panel.innerHTML = this.itemArr.join('');
}
this.doScroll = function() {
with (oRotator) {
if (sAmount < height) {
sAmount ++;
panel.style.pixelTop = parseInt(panel.style.pixelTop) - 1;
oTime = window.setTimeout('oRotator.doScroll()', 10);
} else {
sAmount = 0;
itemArr.push(itemArr.shift());
setPanelContent();
panel.style.pixelTop = parseInt(panel.style.pixelTop) + height;
window.clearTimeout(oTime);
}
}
}
}
window.onload = function() {
var _width = 50, _height = 30, _delay = 3000;
var _array = [];
_array[_array.length] = ['http://www.51js.com/', 'http://www.iecn.net/', 'http://www.ctrl.com.cn/', 'http://www.163.com/', 'http://www.sina.com.cn/'];
_array[_array.length] = ['images/default/profile.gif', 'images/default/email.gif', 'images/default/pm.gif', 'images/default/edit.gif', 'images/default/quote.gif'];
_array[_array.length] = ['无忧脚本', 'Web中文网', '开创互联', '网易', '新浪'];
oRotator = new Rotator(self.oContainer, _width, _height);
oRotator.drawRotator(_array, _delay);
oInterval = window.setInterval('oRotator.doScroll()', _delay);
}
</script>
<br><br>
<div id="oContainer" align="center"></div>
posted on 2006-04-03 14:42
汪杰 阅读(254)
评论(0) 编辑 收藏 引用 所属分类:
hengxing网站js