用javascript标记like
您好,我又发现了一个很棒的脚本,它几乎可以实现我想要的功能。问题是,当页面加载时,它不会自动移动。我们可以将它更改为这样吗? 这个想法是让滚动的消息,我想让它成为一个循环,这样我有一个消息,它将从上到下移动,但它永远不会停止移动像一个字幕 提前谢谢用javascript标记like,javascript,marquee,Javascript,Marquee,您好,我又发现了一个很棒的脚本,它几乎可以实现我想要的功能。问题是,当页面加载时,它不会自动移动。我们可以将它更改为这样吗? 这个想法是让滚动的消息,我想让它成为一个循环,这样我有一个消息,它将从上到下移动,但它永远不会停止移动像一个字幕 提前谢谢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<!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>
无标题文件
scrollStep=1
timerUp=“”
timerDown=“”
函数toTop(id){
document.getElementById(id).scrollTop=0
}
函数scrollDivDown(id){
clearTimeout(timerDown)
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout(“scrollDivDown(“+id+”)”),10)
}
功能滚动分割(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout(“scrollDivUp(“+id+”)”),10)
}
函数toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}
函数stopMe(){
clearTimeout(timerDown)
clearTimeout(timerUp)
}
#展示{
宽度:200px;
高度:150像素;
溢出:隐藏;
文本对齐:左对齐;
边框:1px纯黑;
}
层内容
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
虚拟文本
结束
我想这样做,这样它会形成一个循环:
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()">
功能向下滚动(id){
clearTimeout(timerDown)
document.getElementById(id).scrollTop+=scrollStep
if(document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight){
document.getElementById(id).scrollTop=0
}
}
在这个div下面是消息Try window.onload,它围绕着您希望在页面加载时运行的代码
window.onload=function(){…yourcode…}代码>您可以尝试用以下方式将代码包装到
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>
window.load=函数(){
scrollStep=1
timerUp=“”
timerDown=“”
函数toTop(id){
document.getElementById(id).scrollTop=0
}
函数scrollDivDown(id){
clearTimeout(timerDown)
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout(“scrollDivDown(“+id+”)”),10)
}
功能滚动分割(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout(“scrollDivUp(“+id+”)”),10)
}
函数toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}
函数stopMe(){
clearTimeout(timerDown)
clearTimeout(timerUp)
}
};
好的,我在这里找到了一个完美的解决方案!!
页面加载时它应该做什么?你期望它有什么样的行为?我希望它能自己从下到上移动,而不需要靠近鼠标或点击任何东西。这就是你想要的吗?