2010-07-19 4 views
0

Je suis en train de créer une liste de menu déroulant en JavaScript et je suit un tutoriel http://javascript.internet.com/navigation/menu-scroll.htmlmenu déroulant en JavaScript

Mais rien ne figure sur ma page. C'est ce que j'ai essayé:

<!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 ([email protected]) --> 
<!-- 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> 

Toute aide s'il vous plaît ?? :)

Merci beaucoup C.

Répondre

1

scrollItems Modifier() à ce code

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); 
    } 
} 

Voir s'il vous plaît si elle fonctionne bien avec vous

1

Modification au code de Kronass est bon. En fait, j'ai réussi à faire fonctionner le code, mais il m'a parié.

Vous devez également noter que votre corps ne doit pas contenir de virgule, mais un point-virgule.

dire que vous avez:

<body onLoad="buildMenu(), scrollItems();"> 

qui devrait être

<body onLoad="buildMenu(); scrollItems();"> 

Dans votre style HTML, vous devriez avoir

visibility: visible; 

PAS

visibility: show; 

La raison pour laquelle le code d'origine ne fonctionne pas, c'est qu'il est TRES vieux. (en termes Internet)