文字滚动的js函数


//scrollBodyId: String 内部滚动div的id
//scrollBoxId: String 外面限制div的id
//showHeight: Int 限制显示高度
//showWidth: Int 限制显示宽度
//lineHeight: Int 每行的高度
//stopTime: Int 间隔停止的时间(毫秒)
//speed: Int 滚动速度(毫秒,越小越快)
var ScrollObj = function(scrollBodyId,scrollBoxId,showHeight,showWidth,lineHeight,stopTime,speed) {
this.obj = document.getElementById(scrollBodyId);
this.box = document.getElementById(scrollBoxId);

this.style = this.obj.style;
this.defaultHeight = this.obj.offsetHeight;

this.obj.innerHTML += this.obj.innerHTML;
this.obj.style.position = "relative";

this.box.style.height = showHeight;
this.box.style.width = showWidth;
this.box.style.overflow = "hidden";

this.scrollUp = doScrollUp;

this.stopScroll = false;

this.curLineHeight = 0;
this.lineHeight = lineHeight;
this.curStopTime = 0;
this.stopTime = stopTime;
this.speed = speed;

this.style.top = lineHeight;

this.object = scrollBodyId + "Object";
eval(this.object + "=this");
setInterval(this.object+".scrollUp()",speed);
this.obj.onmouseover=new Function(this.object+".stopScroll=true");
this.obj.onmouseout=new Function(this.object+".stopScroll=false");
}
function doScrollUp(){
if( this.stopScroll == true )
return;
this.curLineHeight += 1;
if( this.curLineHeight >= this.lineHeight ){
this.curStopTime += 1;
if( this.curStopTime >= this.stopTime ){
this.curLineHeight = 0;
this.curStopTime = 0;
}
}
else{
this.style.top = parseInt(this.style.top) - 1;
if( -parseInt(this.style.top) >= this.defaultHeight ){
this.style.top = 0;
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值