English 中文(简体)
在子菜单上徘徊时保持悬停状态
原标题:Make a hover state remain while hovering on submenu items

我怎样才能让顶层的:hover State 停留在顶层, 当鼠标在此菜单中的子菜单上鼠标时? 它可能很简单, 但我似乎无法成功。 我尝试过做鼠标 Enter, 但我很可能做错了, 因为我对jQuery知之甚少。 感谢您事先!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Menu</title>


<link rel="stylesheet" type="text/css" href="droplinetabs.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script src="droplinemenu.js" type="text/javascript"></script>

<script type="text/javascript">

//build menu with DIV ID="myslidemenu" on page:
droplinemenu.buildmenu("droplinetabs1")


</script>




</head>

<body>

<div id="droplinetabs1" class="droplinetabs">
<ul id="base">
<li><a href="#">Stuff to Do</a>
  <ul>
  <li class="base"><a href="#">Activities 1.1</a>     
    <ul>
          <li><a href="#">Cricket</a></li>
          <li><a href="#">Rugby</a></li>
          <li><a href="#">Soccer</a></li>
         <li><a href="#"> Football</a></li>
      </ul>
  </li>
  <li><a href="#">Activities 1.2</a>      
        <ul>
          <li><a href="#">Eating</a></li>
          <li><a href="#">Cooking</a></li>
          <li><a href="#">Baking</a></li>
      </ul>
  </li>
  <li><a href="#">Activities 1.3</a>
      <ul>
        <li><a href="#">Music</a></li>
        <li><a href="#">Chess</a></li>
        <li><a href="#">Reading</a></li>
        <li><a href="#">Scribbling</a></li>
      </ul>
    </li>
  </ul>
</li>
<li class="base"><a href="#">More Stuff to Do</a>
  <ul>
  <li><a href="#">Activities 2.1</a>      
    <ul>
        <li><a href="#">Cricket</a></li>
        <li><a href="#">Rugby</a></li>
        <li><a href="#">Soccer</a></li>
        <li><a href="#"> Football</a></li>
      </ul>
  </li>
  <li><a href="#">Activities 2.2</a>      
    <ul>
          <li><a href="#">Eating</a></li>
          <li><a href="#">Cooking</a></li>
          <li><a href="#">Baking</a></li>
   </ul>
  </li>
  <li><a href="#">Activities 2.3</a>
      <ul>
         <li><a href="#">Music</a></li>
         <li><a href="#">Chess</a></li>
         <li><a href="#">Reading</a></li>
         <li><a href="#">Scribbling</a></li>
      </ul>
    </li>
  </ul>
</li>
<li class="base"><a href="#">Even More</a>
  <ul>
  <li><a href="#">Activities 3.1</a>      
    <ul>
      <li><a href="#">Cricket</a></li>
      <li><a href="#">Rugby</a></li>
      <li><a href="#">Soccer</a></li>
      <li><a href="#">Football</a></li>
     </ul>
  </li>
  <li><a href="#">Activities 3.2</a>      
    <ul>
      <li><a href="#">Eating</a></li>
      <li><a href="#">Cooking</a></li>
      <li><a href="#">Baking</a></li>
    </ul>
  </li>
  <li><a href="#">Activities 3.3</a>
    <ul>
      <li><a href="#">Music</a></li>
      <li><a href="#">Chess</a></li>
      <li><a href="#">Reading</a></li>
      <li><a href="#">Scribbling</a></li>
      </ul>
   </li>
</ul>
</li>
</ul>
</div>






</body>
</html>

var droplinemenu={



arrowimage: {classname:  downarrowclass , src:  down.gif , leftpadding: 5}, //customize down arrow image
animateduration: {over: 1, out: 1}, //duration of slide in/ out animation, in milliseconds



buildmenu:function(menuid){
    jQuery(document).ready(function($){
        var $mainmenu=$("#"+menuid+">ul")
        var $headers=$mainmenu.find("ul").parent()
        $headers.each(function(i){
            var $curobj=$(this)
            var $subul=$(this).find( ul:eq(0) )
            this._dimensions={h:$curobj.find( a:eq(0) ).outerHeight()}
            this.istopheader=$curobj.parents("ul").length==1? true : false
            if (!this.istopheader)
                $subul.css({left:0, top:this._dimensions.h})
            var $innerheader=$curobj.children( a ).eq(0)
            $innerheader=($innerheader.children().eq(0).is( span ))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that

            $curobj.hover(
                function(e){
                    var $targetul=$(this).children("ul:eq(0)")
                    if ($targetul.queue().length<=1) //if 1 or less queued animations
                        if (this.istopheader)
                            $targetul.css({left: $mainmenu.position().left, top: $mainmenu.position().top+this._dimensions.h})
                        if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
                            $mainmenu.find( ul ).css({overflow: (this.istopheader)?  hidden  :  visible })
                        $targetul.dequeue().slideDown(droplinemenu.animateduration.over)
                },
                function(e){
                    var $targetul=$(this).children("ul:eq(0)")
                    $targetul.dequeue().slideUp(droplinemenu.animateduration.out)
                }
            ) //end hover
        }) //end $headers.each()
        $mainmenu.find("ul").css({display: none , visibility: visible , width:$mainmenu.width()})
    }) //end document.ready
}
}
最佳回答

添加 $( 这样) 。 addClass( 悬盘) ; 到您的悬盘输入功能 ; $( this. removeClass( 悬盘) ; 到您的悬盘流出功能, 并在您的 CSS 中添加 < code>li. hover{/ * css, 具体为 < */ / code > 。

        $curobj.hover(
            function(e){
                var $targetul=$(this).children("ul:eq(0)")
                                    $(this).addClass( hover );
                if ($targetul.queue().length<=1) //if 1 or less queued animations
                    if (this.istopheader)
                        $targetul.css({left: $mainmenu.position().left, top: $mainmenu.position().top+this._dimensions.h})
                    if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
                        $mainmenu.find( ul ).css({overflow: (this.istopheader)?  hidden  :  visible })
                    $targetul.dequeue().slideDown(droplinemenu.animateduration.over)
            },
            function(e){
                var $targetul=$(this).children("ul:eq(0)")
                                    $(this).removeClass( hover );
                $targetul.dequeue().slideUp(droplinemenu.animateduration.out)
            }
        ) //end hover

或者,如果你想要一个纯粹的 CSS 替代品。这是我使用每个网站的一个。

nav ul{
    margin-bottom:10px;
    list-style-image:none
}
nav>ul>li{
    display:inline-block;/* float:left needed for some designs */
    font-size:20px;
    text-align:center;
    position:relative;
    z-index:950
}
nav a{
    text-decoration:none;
    display:block;
    color:#000;
    padding:8px 0
}
nav li ul{
    display:none;
    position:absolute;
    padding:0 8px;
    margin:0
}
nav li:hover ul{display:block}
nav li li{
    font-size:15px;
    float:none;
    width:100%;
    z-index:999
}

注意,这是个骨架,不好看

HTML也很简单:

<nav>
    <ul>
        <li><a href="#">top level item</a>
            <ul>
                <li><a href="#">sub-item</a></li>
            </ul>
        </li>
        <li>top level item</li>
    </ul>
</nav>
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.