JavaScript标题新闻的定时翻滚(IE,FF,Opera,Safari,Chrome)
2009-06-30 05:10:00 来源:WEB开发网下面是主要代码:
程序代码
var Scroll=Class.create();
Scroll.PRototype={
//第一个参数定义要滚动的区域,第二个参数定义每次滚动的高度
initialize:function(element,height,delay){
this.element=$(element);
this.element.innerHTML+=this.element.innerHTML;
this.height=height;
this.delay=delay*1000;
this.maxHeight=this.element.scrollHeight/2;
this.counter=0;
this.scroll();
this.timer="";
this.element.onmouSEOver=this.stop.bind(this);
this.element.onmouseout=function(){this.timer=setTimeout(this.scroll.bind(this),1000);}.bind(this);
},
scroll:function(){
if(this.element.scrollTop<this.maxHeight){
this.element.scrollTop++;
this.counter++;
}else{
this.element.scrollTop=0;
this.counter=0;
}
if(this.counter<this.height){
this.timer=setTimeout(this.scroll.bind(this),20);
}else{
this.counter=0;
this.timer=setTimeout(this.scroll.bind(this),this.delay);
}
},
stop:function(){
clearTimeout(this.timer);
}
}
Tags:JavaScript 标题 新闻
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接