通过将其设置为滚动溢出,假设高度固定,滚动条将弹出,您可以手动滚动。当然,当滚动条恢复自动滚动时,您需要再次隐藏滚动条,因此需要两个函数来设置样式。
<script language="javascript">
i = 0;
var speed = 1,t1=null;
function startScroll(){
document.getElementById("content").style.overflowY="hidden";
scroll();
}
function stopScroll(){
clearTimeout(t1);
document.getElementById("content").style.overflowY="scroll";
}
function scroll() {
i = i + speed;
var div = document.getElementById("content");
div.scrollTop = i;
if (i > div.scrollHeight - 160) { i = 0; }
t1 = setTimeout("scroll()", 100);
}
</script>
HTML更改:
<div id="content" value="Pause" onmouseover="pauseScroll()" onmouseout="startScroll()">