2012-12-27 293 views
-1

我有一個垂直滾動腳本,對我來說很好,但問題是它會在一段時間後停下來。如何修改腳本,以便它可以一次又一次地從頭到尾無限滾動?
下面是代碼:無限垂直滾動條

<html> 
<head> 
<style type="text/css"> 
.frame { 
font:12px arial; 
width:200; 
height:300; 
border:none; 
overflow: hidden; 
border:1px solid black; 
padding:5; 
} 
</style> 
<script language="javascript"> 
i = 0 
var speed = 1 
function scroll() { 
i = i + speed 
var div = document.getElementById("news") 
div.scrollTop = i 
if (i > div.scrollHeight - 160) {i = 0} 
t1=setTimeout("scroll()",100) 
} 
</script> 
</head> 
<body onload="scroll()"> 
<div class="frame" id="news" onmouseover="clearTimeout(t1)" onmouseout="scroll()" > 
Some Text text 1<br> 
Some Text text 2<br> 
Some Text text 3<br> 
Some Text text 4<br> 
Some Text text 5<br> 
Some Text text 6<br> 
Some Text text 7<br> 
Some Text text 8<br> 
Some Text text 9<br> 
Some Text text 10<br> 
Some Text text 11<br> 
Some Text text 12<br> 
Some Text text 13<br> 
Some Text text 14<br> 
Some Text text 15<br> 
Some Text text 16<br> 
Some Text text 17<br> 
Some Text text 18<br> 
Some Text text 19<br> 
Some Text text 20<br> 
Some Text text 21<br> 
</div> 
</body> 
</html> 
+0

你想說什麼的JavaScript控制檯何時停止工作? – Oded

回答

1

它實際上沒有停止。
嘗試更新,如果()條件

if (i > div.scrollHeight - 300) {i = 0} 
+0

eee謝謝你 –

0

您的問題是,你只scrollHeight屬性後,將其復位-160

應該是scrollHeight屬性 - divHeight