使“jsddm”菜单列出子菜单

时间:2013-02-14 19:46:13

标签: javascript jquery html css menu

你可以帮我把这个jquery / css / menu也显示出第二级吗?

这是代码:

HTML

<ul id="jsddm">
    <li><a href="#">JavaScript</a>
        <ul>
            <li><a href="#">Drop Down Menu</a></li>
            <li><a href="#">jQuery Plugin</a></li>
            <li><a href="#">Ajax Navigation</a></li>
        </ul>
    </li>
    <li><a href="#">Effect</a>
        <ul>
            <li><a href="#">Slide Effect</a></li>
            <li><a href="#">Fade Effect</a></li>
            <li><a href="#">Opacity Mode</a></li>
            <li><a href="#">Drop Shadow</a></li>
            <li><a href="#">Semitransparent</a></li>
        </ul>
    </li>
    <li><a href="#">Navigation</a></li>
    <li><a href="#">HTML/CSS</a></li>
    <li><a href="#">Help</a></li>
</ul>

CSS

#jsddm
{   margin: 0;
    padding: 0}

    #jsddm li
    {   float: left;
        list-style: none;
        font: 12px Tahoma, Arial}

    #jsddm li a
    {   display: block;
        background: #20548E;
        padding: 5px 12px;
        text-decoration: none;
        border-right: 1px solid white;
        width: 70px;
        color: #EAFFED;
        white-space: nowrap}

    #jsddm li a:hover
    {   background: #1A4473}

        #jsddm li ul
        {   margin: 0;
            padding: 0;
            position: absolute;
            visibility: hidden;
            border-top: 1px solid white}

        #jsddm li ul li
        {   float: none;
            display: inline}

        #jsddm li ul li a
        {   width: auto;
            background: #9F1B1B}

        #jsddm li ul li a:hover
        {   background: #7F1616}

JQUERY

    var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

如何再插入一个级别菜单并使其正常工作?我已经被困在这里几天了。

谢谢!

1 个答案:

答案 0 :(得分:0)

如何不使用jQuery并只使用CSS作为菜单?

http://jsfiddle.net/Sjhab/

<ul id="jsddm">
<li><a href="#">JavaScript</a>
<ul>
    <li><a href="#">Drop Down Menu</a></li>
    <li><a href="#">jQuery Plugin</a></li>
    <li class="b"><a href="#">Ajax Navigation</a>
        <ul>
            <li><a href="#">AJAXIFY</a></li>
        </ul>
    </li>
</ul>
</li>
<li><a href="#">Effect</a>
<ul>
    <li><a href="#">Slide Effect</a></li>
    <li><a href="#">Fade Effect</a></li>
    <li><a href="#">Opacity Mode</a></li>
    <li><a href="#">Drop Shadow</a></li>
    <li><a href="#">Semitransparent</a></li>
</ul>
</li>
<li><a href="#">Navigation</a></li>
<li><a href="#">HTML/CSS</a></li>
<li><a href="#">Help</a></li>
</ul>



#jsddm
{ margin: 0; padding: 0}

#jsddm li
{   float: left;
list-style: none;
font: 12px Tahoma, Arial}

#jsddm li a
{   display: block;
background: #20548E;
padding: 5px 12px;
text-decoration: none;
border-right: 1px solid white;
width: 70px;
color: #EAFFED;
white-space: nowrap}

#jsddm li a:hover
{   background: #1A4473}

#jsddm li ul
{   margin: 0;
    padding: 0;
    position: absolute;
    visibility: hidden;
    border-top: 1px solid white;
    opacity: 0;
}

#jsddm > li:hover ul,
#jsddm > li:hover ul li:hover ul
{
    visibility: visible;
    opacity: 1;
  -webkit-transition: all .2s ease-in-out;
  -moz-transition: all .2s ease-in-out;
  -ms-transition: all .2s ease-in-out;
  -o-transition: all .2s ease-in-out;
  transition: all .2s ease-in-out;    
}

#jsddm ul {

-webkit-transition: all .5s ease-out .5s;
-moz-transition: all .5s ease-out .5s;
-ms-transition: all .5s ease-out .5s;
-o-transition: all 5s ease-out.5s;
transition: all .5s ease-out.5s;
}


#jsddm > li:hover ul li ul {
    visibility: hidden;
}


#jsddm li ul li
{   float: none;
    display: inline;
    position: relative;
}

#jsddm li ul li a
{   width: auto;
    background: #9F1B1B}

#jsddm li ul li a:hover
{   background: #7F1616}