简体   繁体   English

在javascript问题中创建菜单

[英]creating a menu in javascript issues

I have created a menu using js and css. 我用js和css创建了一个菜单。 Each li in the top level ul has a specific background image also a specific onmouseover image. 顶级ul中的每个li都具有特定的背景图像,也是特定的onmouseover图像。

Everything is working fine, EXCEPT the onmouseover background whenever I have a submenu under it. 一切都工作正常,除了onmouseover背景,每当我有一个子菜单。 Please check the vertical menu under the following link: http://www.balouta.com/Autostar3/testmenu/test.html 请查看以下链接下的垂直菜单: http//www.balouta.com/Autostar3/testmenu/test.html

The Javascript used is the following: 使用的Javascript如下:

var menuids=new Array("verticalmenu")
var submenuoffset=0 

function createcssmenu(){

for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){

    ultags[t].parentNode.onmouseover=function(){ 

    this.getElementsByTagName("ul")[0].style.right=this.parentNode.offsetWidth+submenuoffset+"px"
    this.getElementsByTagName("ul")[0].style.display="block"

    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
  }
}


if (window.addEventListener)
window.addEventListener("load", createcssmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu)

The problem is that your hover over a top level menu displays a div(sub menu) that hides the content of top menu beneath so no hover for a (of top menu ) is triggered . 问题是,你将鼠标悬停在顶级菜单显示a隐藏的下方所以没有悬停顶部菜单的内容DIV(子菜单) a (顶部菜单)被触发。

A small fix would be to remove the width for the items that have submenu. 一个小的修复方法是删除具有子菜单的项目的宽度。

remove the following line : width: 225px; 删除以下行: width: 225px; (line 81) in the css (第81行)在CSS中

Do the same for all the other menus that has submenu. 对具有子菜单的所有其他菜单执行相同操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM