先了解一下對象的幾個的屬性:
innerHTML:設置或獲取位於對象起始和結束標簽內的 HTML
scrollHeight: 獲取對象的滾動高度。
scrollLeft:設置或獲取位於對象左邊界和窗口中目前可見內容的最左端之間的距離
scrollTop:設置或獲取位於對象最頂端和窗口中可見內容的最頂端之間的距離
scrollWidth:獲取對象的滾動寬度
offsetHeight:獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的高度
offsetLeft:獲取對象相對於版面或由 offsetParent 屬性指定的父坐標的計算左側位置
offsetTop:獲取對象相對於版面或由 offsetTop 屬性指定的父坐標的計算頂端位置
offsetWidth:獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的寬度
好,先看這個向上滾動的代碼:
<base href="替換www.flash8.net">
<div id=demo style=overflow:hidden;height:100;width:90;background:#214984;color:#ffffff><div id=demo1>
<img src="替換webdesign.chinaitlab.com/dwsl/images/flash8.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/flashempire.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/linklogo/shlogo.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/deskcity.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/linklogo/5dmeng.gif">
<img src="/newasp/article/UploadPic/2006928/2006928183335360.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/flashskylogo.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/5dlogo88.gif">
<img src="/newasp/article/UploadPic/2006928/2006928183335284.gif">
</div>
<div id=demo2></div>
</div>
<script>
var speed=30
demo2.innerHTML=demo1.innerHTML file://克隆demo1為demo2
function Marquee(){
if(demo2.offsetTop-demo.scrollTop<=0) file://當滾動至demo1與demo2交界時
demo.scrollTop-=demo1.offsetHeight file://demo跳到最頂端
else{
demo.scrollTop++
}
}
var MyMar=setInterval(Marquee,speed) file://設置定時器
demo.onmouseover=function() {clearInterval(MyMar)}//鼠標移上時清除定時器達到滾動停止的目的
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}//鼠標移開時重設定時器
</script>
向下滾動:
<base href="替換www.flash8.net">
<div id=demo style=overflow:hidden;height:100;width:90;background:#214984;color:#ffffff><div id=demo1>
<img src="替換webdesign.chinaitlab.com/dwsl/images/flash8.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/flashempire.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/linklogo/shlogo.gif">
<img src="替換webdesign.chinaitlab.com/dwsl/images/link/desk