function createMenu(menuName,menuTitle,menuEntries,left,width) { numEntries = menuEntries.length; document.write('<div class="menuTitle" style="left:0px; width:100px;"'); document.write('onMouseover="menuToggle(\'' + menuName + '\');"'); document.write('onMouseout="menuToggle(\'' + menuName + '\');">'); document.write(menuTitle); document.write('</div>'); document.write('<div id="myMenu" class="menu" style="left:0px; width:100px;"'); document.write('onMouseout="menuToggle(\'' + menuName + '\')">'); for (i = 0; i < numEntries; i++) { document.write('<a href="' + menuEntries[i].url + '" class="menuEntry">' + menuEntries[i].entry + '</a><br>'); } document.write('</div>'); } function menuToggle(target) { targetMenu = (document.getElementById) ? document.getElementById(target).style : eval("document." + target); targetMenu.top = (parseInt(targetMenu.top) == 22) ? -2000 : 22; }
this is javascript to create a drop-down menu that crashes when the mouse hovers over it - this is from a book called javascript in 10 simple steps or less from Arman Danesh. He is a great author and will probably explain it much better than me, but here goes:
what you do is create a function with predefined variables, as indicated in (). the numEntries ... line sets the value of the numEntries variable to the length of the predefined menuEntries variable. In other words, (in this example, the number of programmed entries is three, making numEntries = 3), however many of the entries you encode are numEntries.
document.write stuff may look confusing, but it's just javascript code that contains HTML code, because just put a div on it to break the program, since you put it in script tags. if you donβt understand me at some point, just ask and I will tell you what's in the textbook when I have it on me later.
As for the first function, the second is what makes the menu drop down menu a mouse cursor. I donβt know how to explain this clearly to you without quoting the book, but I will try, if you need me to explain it. I can give you the whole example, if you need HTML code to display the menu too, I have it on my computer.
Hope this helps, and please just ask if I need to sort out something. I will continue to explore how to change it for the touch screen for you x
user1703470
source share