js 上下文字滚动效果
js实现的文字向上滚动效果,适合文字公告等。
test
#textHeight{line-height:25px; height:25px; overflow:hidden; width:150px; font-size:12px; border:solid 1px #666;}
function ScrollText(content){
this.Delay=10;
this.Amount=1;
this.Direction="up";
this.Timeout=1000;
this.ScrollContent=this.gid(content);
this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
}
ScrollText.prototype.gid=function(element){
return document.getElementById(element);
}
ScrollText.prototype.Stop=function(){
clearTimeout(this.AutoScrollTimer);
clearTimeout(this.ScrollTimer);
}
ScrollText.prototype.Start=function(){
clearTimeout(this.AutoScrollTimer);
this.AutoScrollTimer=setTimeout(this.GetFunction(this,"AutoScroll"),this.Timeout);
}
ScrollText.prototype.AutoScroll=function(){
if(this.Direction=="up"){
if(parseInt(this.ScrollContent.scrollTop)>=parseInt(this.ScrollContent.scrollHeight)/2){
this.ScrollContent.scrollTop=0;
clearTimeout(this.AutoScrollTimer);
this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
return;
}
this.ScrollContent.scrollTop += this.Amount;
}else
{
if(parseInt(this.ScrollContent.scrollTop)
博客园 |
我们 |
csdn |
蓝色理想 |
51js |
var scrollup = new ScrollText("textHeight");
scrollup.Start();
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]