我正在尝试用JavaScript创建一个可滚动的菜单列表,我正在按照教程进行操作 http://javascript.internet.com/navigation/menu-scroll.html
但我的页面上没有任何内容。这就是我的尝试:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script type="text/javascript" src="ScrollMenu.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Randy Bennett (rbennett@thezone.net) -->
<!-- Web Site: http://home.thezone.net/~rbennett/utility/javahead.htm -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function buildMenu() {
speed=35;
topdistance=100;
items=6;
y=-50;
ob=1;
if (navigator.appName == "Netscape") {
v=".top=",dS="document.",sD="";
}
else {
v=".pixelTop=",dS="",sD=".style";
}
}
function scrollItems() {
if (ob<items+1) {
objectX="object"+ob; y+=10; eval(dS + objectX + sD + v + y);
if (y<topdistance) setTimeout("scrollItems()",speed);
else y=-50, topdistance+=40, ob+=1, setTimeout("scrollItems()",speed);
}
}
// End -->
</SCRIPT>
</head>
<body onLoad="buildMenu(), scrollItems();">
<a href="pic.html">hello</a>
<a href="pic.html">Link 1!</a>
<a href="pic.html">Link 1!</a>
<a href="pic.html">Link 1!</a>
<a href="pic.html">Link 1!</a>
<a href="pic.html">Link 1!</a>
<div id="object1" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 1!</a>
</td>
</table>
</div>
<div id="object2" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 2!</a>
</td>
</table>
</div>
<div id="object3" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 3!</a>
</td>
</table>
</div>
<div id="object4" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 4!</a>
</td>
</table>
</div>
<div id="object5" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 5!</a>
</td>
</table>
</div>
<div id="object6" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">
<table border=1 width=150 bgcolor=80FFFF>
<td>
<a href="pic.html">Link 6!</a>
</td>
</table>
</div>
</body>
</html>
有任何帮助吗? :)
非常感谢 下进行。
答案 0 :(得分:1)
将scrollItems()更改为此代码
function scrollItems() {
if (ob<items+1) {
objectX="object"+ob; y+=10;
document.getElementById(objectX).style.top = y + "px"
if (y<topdistance) setTimeout("scrollItems()",speed);
else y=-50, topdistance+=40, ob+=1, setTimeout("scrollItems()",speed);
}
}
如果可以和你一起工作,请查看
答案 1 :(得分:1)
更改为Kronass的代码很好。我实际上也得到了代码,但他/她打赌我。
你还应该注意,你的身体上载不应该有逗号,而是分号。
即。你有:
<body onLoad="buildMenu(), scrollItems();">
哪个应该是
<body onLoad="buildMenu(); scrollItems();">
在您的HTML样式中,您应该
visibility: visible;
不是
visibility: show;
原始代码不起作用的原因是它非常古老。 (以互联网术语)