-1

再次您好,我发现了一个很棒的脚本,它几乎可以完成我想要的问题是当页面加载时它不会自行移动我们可以更改它来做到这一点吗?我的想法是让消息向下滚动,我想让它形成一个循环,这样我就有一条消息,它会从上到下移动,但它永远不会像选框一样停止移动,提前谢谢!

  <!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">

scrollStep=1

timerUp=""
timerDown=""

function toTop(id){
document.getElementById(id).scrollTop=0
}

function scrollDivDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout("scrollDivDown('"+id+"')",10)
}

function scrollDivUp(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

function toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
clearTimeout(timerDown) 
clearTimeout(timerUp)
}

</script>

<style>
#display{
width:200px;
height:150px;
overflow:hidden;
text-align:left;
border:1px solid black;
}
</style>
</head>

<body>
<a href="#null" onclick="toTop('display')">Top</a> 
<a href="#null" onmouseover="scrollDivDown('display')" onmouseout="stopMe()">ScrollDown</a> 
<a href="#null" onmouseover="scrollDivUp('display')" onmouseout="stopMe()">Scroll Up</a>
<a href="#null" onclick="toBottom('display')">Bottom</a>
<div id="display">

<b>LAYER CONTENTS</b>

<P>Dummy Text<P>Dummy Text<P>Dummy Text<P>Dummy Text
<P>Dummy Text<P>Dummy Text<P>Dummy Text<P>Dummy Text
<P>Dummy Text<P>Dummy Text<P>Dummy Text<P>Dummy Text
<P>Dummy Text<P>Dummy Text<P>Dummy Text<P>End

</div>
</body>
</html>

我想做这样的事情,所以它会循环:

function scrollDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
if (document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight){
    document.getElementById(id).scrollTop=0
    }

}






<div id="display" onmouseout="scrollDown('display')" onmouseover="stopMe()">

在这个 div 下它的消息

4

3 回答 3

0

好的,我在这里找到了一个完美的解决方案! http://jscroller2.markusbordihn.de/

于 2013-07-19T10:01:17.000 回答
0

围绕您想要在页面加载时运行的代码尝试 window.onload。

window.onload = function() { ...yourcode... };

于 2013-07-11T11:24:29.673 回答
0

您可以尝试将您的代码包装成以下方式进入

windows.load=function(){//你的代码}

由于脚本在加载文档之前加载

<script type="text/javascript">
window.load = function(){
scrollStep=1

timerUp=""
timerDown=""

function toTop(id){
document.getElementById(id).scrollTop=0
}

function scrollDivDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout("scrollDivDown('"+id+"')",10)
}

function scrollDivUp(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

function toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
clearTimeout(timerDown) 
clearTimeout(timerUp)
}
};

</script>
于 2013-07-11T11:28:33.167 回答