<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml ">
<头>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<标题></标题>
</头>
<正文>
<脚本类型=“文本/javascript”>
var $ = 函数(id){
返回“字符串”== typeof id ? document.getElementById(id) : id;
};
var 类 = {
创建:函数(){
返回函数(){
this.initialize.apply(this, 参数);
}
}
}
Object.extend = 函数(目标,源){
for (var 源中的属性) {
目的地[属性] = 源[属性];
}
返回目的地;
}
函数 addEventHandler(oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} 别的 {
oTarget["on" + sEventType] = fnHandler;
}
};
var Scroller = Class.create();
Scroller.prototype = {
初始化:函数(idScroller,idScrollMid,选项){
var oScroll = this, oScroller = $(idScroller), oScrollMid = $(idScrollMid);
this.heightScroller = oScroller.offsetHeight;
this.heightList = oScrollMid.offsetHeight;
if(this.heightList <= this.heightScroller) 返回;
oScroller.style.overflow = "隐藏";
oScrollMid.appendChild(oScrollMid.cloneNode(true));
this.oScroller = oScroller;
this.timer = null;
this.SetOptions(选项);
this.side = 1;//1是上-1是下
开关(this.options.Side){
案例“向下”:
this.side = -1;
休息;
案例“向上”:
默认 :
这个.side = 1;
}
addEventHandler(oScrollMid , "mouSEOver", function() { oScroll.Stop(); });
addEventHandler(oScrollMid , "mouseout", function() { oScroll.Start(); });
if(this.options.PauseStep <= 0 || this.options.PauseHeight <= 0) this.options.PauseStep = this.options.PauseHeight = 0;
这个.暂停= 0;
this.Start();
},
//设置默认属性
设置选项:函数(选项){
this.options = {//默认值
Step: 1,//每次变化的px量
时间: 20,//速度(越大越慢)
Side: "up",//滚动方向:"up"是上,"down"是下
PauseHeight: 0,//隔多高停一次
PauseStep: 1000//停顿时间(PauseHeight大于0该参数才有效)
};
Object.extend(this.options, 选项 || {});
},
//滚动
滚动:函数(){
var iScroll = this.oScroller.scrollTop, iHeight = this.heightList, time = this.options.Time, oScroll = this, iStep = this.options.Step * this.side;
if(this.side > 0){
if(iScroll >= (iHeight * 2 - this.heightScroller)){ iScroll -= iHeight; }
} 别的 {
if(iScroll <= 0){ iScroll += iHeight; }
}
if(this.options.PauseHeight > 0){
if(this.Pause >= this.options.PauseHeight){
时间 = this.options.PauseStep;
这个.暂停= 0;
} 别的 {
this.Pause += Math.abs(iStep);
this.oScroller.scrollTop = iScroll + iStep;
}
} else { this.oScroller.scrollTop = iScroll + iStep; }
this.timer = window.setTimeout(function(){ oScroll.Scroll(); }, time);
},
//开始
开始:函数(){
this.Scroll();
},
//停止
停止:函数(){
清除超时(this.timer);
}
};
窗口.onload = 函数(){
新的 Scroller("idScroller", "idScrollMid",{ PauseHeight:25 });
}
</脚本>
<风格>
#idScroller *{边距:0px;填充:0px;}
#idScroller{行高:25px;宽度:100%;高度:25px;溢出:隐藏;边框:1px实线#000000;}
#idScroller ul{宽度:100%}
#idScroller li{宽度:20%; 浮动:左;溢出:隐藏;列表样式:无;}
</风格>
<div id="idScroller">
<div id="idScrollMid">
<ul>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
<li> <a href="http://www.devdao.com/">www.devdao.com</a></li>
</ul>
<div style="clear:both;"></div>
</div>
</div>
</正文>
</html>