var isDown
window.onload = function () {
//滚动条索取对象(这里使用整个页面,确保页面有滚动条)
camera = document.body
isDown = true //默认向下
c = setInterval(gundong, 10)
}
var gundong = function () {
if (isDown) {
camera.scrollTop++ //下降
//如果滚动条超过100的话,就往上
//可以修改这个条件,作为折返的前提
if (camera.scrollTop > 100) {
isDown = false
}
} else {
camera.scrollTop-- //上升
//到达顶部的话,就下降
if (camera.scrollTop == 0) {
isDown = true
}
}
}
模拟一下,控制层的滚动条~<script
language="javascript">
function
sendText()
{
var
e=document.getElementById("div1")
var
inp=document.getElementById("inp")
e.innerText=e.innerText+"\n"+inp.value
//e.scrollTop=e.scrollHeight
}
function
sc()
{
var
e=document.getElementById("div1")
e.scrollTop=e.scrollHeight
}
var
s=setInterval("sc()",200)
</script>
<div
id="div1"
style="border:1px
#ff9966
dashedwidth:400height:100overflow-x:hiddenoverflow-y:scroll">
</div>
<input
type="text"
id="inp"
style="width:300">
<input
type="button"
onclick="sendText()"
value="发送">