<!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>