jQueryUI Accordian Menu - 如何处理没有子菜单的项目

发布于 2024-09-15 12:12:25 字数 2459 浏览 7 评论 0原文

我有一个使用 jQueryUI 的 Accordian 方法的垂直菜单。前两个项目有子菜单,其余项目则没有。我还将事件设置为“悬停”而不是“单击”。

问题:是,当您将鼠标悬停在任何没有子菜单的项目上时,它会隐藏带有子菜单的项目。有没有办法让它始终保持至少一个项目的子菜单打开?或者另一种说法:有没有办法强制没有子菜单的项目不折叠任何其他项目?

这是我的菜单的一个例子......

<ul class="nav" id="menu_left"> 
    <li class="expand"><a href="/category" class="current head">products</a> 
        <ul> 
            <li class="top png first"></li> 
            <li><a href="/category/523">Category</a></li> 
            <li><a href="/category/428" >Category</a></li> 
            <li><a href="/category/498">Category</a></li> 
            <li class="space"><div></div><a href="/category/507">Category</a></li> 
            <li><a href="/category/">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li class="space"><div></div><a href="#">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li class="bottom png"></li> 
        </ul> 
    </li> 
    <li class="expand"><a href="/category/">custom</a> 
        <ul> 
            <li class="top png first"></li> 
            <li><a href="/category">Category</a></li> 
            <li class="space"><div></div><a href="/category/428" >Category</a></li> 
            <li><a href="/category/498">Category</a></li> 
            <li class="bottom png"></li> 
        </ul> 
    </li> 
    <li><a href="javascript:void(0);" class="head" >Contact</a></li> 
    <li><a href="javascript:void(0);" class="head">Blog</a></li> 
    <li><a href="javascript:void(0);" class="head">Feature</a></li> 
</ul>

$('#menu_left').accordion({
    active: 0,
    autoHeight: true,
    animated: 'slide',
    event: 'mouseover',
    header: "> li > :first-child,> :not(li):even",
    collapsible: false,
    navigationFilter: function() {
        return this.href.toLowerCase() == location.href.toLowerCase();
    }
});

I've got a vertical menu using jQueryUI's Accordian method. The first two items have sub-menus and then the rest don't. I also have the event set to 'hover' instead of 'click'.

The problem: is that when you hover over any of the items with no sub-menus, then it hides the one with a sub-menu. Is there a way I can make it so it always keeps at least one item with a sub-menu open? Or another way to say this: is there a way to force items with no sub-menus to not collapse any other items?

Here's an example of my menu...

<ul class="nav" id="menu_left"> 
    <li class="expand"><a href="/category" class="current head">products</a> 
        <ul> 
            <li class="top png first"></li> 
            <li><a href="/category/523">Category</a></li> 
            <li><a href="/category/428" >Category</a></li> 
            <li><a href="/category/498">Category</a></li> 
            <li class="space"><div></div><a href="/category/507">Category</a></li> 
            <li><a href="/category/">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li class="space"><div></div><a href="#">Category</a></li> 
            <li><a href="#">Category</a></li> 
            <li class="bottom png"></li> 
        </ul> 
    </li> 
    <li class="expand"><a href="/category/">custom</a> 
        <ul> 
            <li class="top png first"></li> 
            <li><a href="/category">Category</a></li> 
            <li class="space"><div></div><a href="/category/428" >Category</a></li> 
            <li><a href="/category/498">Category</a></li> 
            <li class="bottom png"></li> 
        </ul> 
    </li> 
    <li><a href="javascript:void(0);" class="head" >Contact</a></li> 
    <li><a href="javascript:void(0);" class="head">Blog</a></li> 
    <li><a href="javascript:void(0);" class="head">Feature</a></li> 
</ul>

$('#menu_left').accordion({
    active: 0,
    autoHeight: true,
    animated: 'slide',
    event: 'mouseover',
    header: "> li > :first-child,> :not(li):even",
    collapsible: false,
    navigationFilter: function() {
        return this.href.toLowerCase() == location.href.toLowerCase();
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柒七 2024-09-22 12:12:25

您可以有两个单独的菜单,并将其样式设置为看起来像一个。

<ul class="nav" id="menu_left"> 
  <li class="expand"><a href="/category" class="current head">products</a> 
    <ul> 
      ...
    </ul> 
  </li> 
  <li class="expand"><a href="/category/">custom</a> 
    <ul> 
      ...
    </ul> 
  </li> 
</ul>
<ul class="nav">
  <li><a href="javascript:void(0);" class="head" >Contact</a></li> 
  <li><a href="javascript:void(0);" class="head">Blog</a></li> 
  <li><a href="javascript:void(0);" class="head">Feature</a></li> 
</ul>

$('#menu_left').accordion({
  ...
});

You could have two separate menus, and just style it to look like one.

<ul class="nav" id="menu_left"> 
  <li class="expand"><a href="/category" class="current head">products</a> 
    <ul> 
      ...
    </ul> 
  </li> 
  <li class="expand"><a href="/category/">custom</a> 
    <ul> 
      ...
    </ul> 
  </li> 
</ul>
<ul class="nav">
  <li><a href="javascript:void(0);" class="head" >Contact</a></li> 
  <li><a href="javascript:void(0);" class="head">Blog</a></li> 
  <li><a href="javascript:void(0);" class="head">Feature</a></li> 
</ul>

$('#menu_left').accordion({
  ...
});
冷夜 2024-09-22 12:12:25

我通过将标题选项更改为如下解决了这个问题...

header: '> li.expand > :first-child,> :not(li):even'

我还将 autoHeight 更改为 false...

autoHeight: false

I solved this by changing the header option to look like this...

header: '> li.expand > :first-child,> :not(li):even'

I also changed autoHeight to false...

autoHeight: false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文