简体   繁体   English

jQuery下拉菜单:不显示一项

[英]jQuery Dropdown Menus: not showing one item

I've created a jQuery dropdown menu that shows div dropdowns on hover. 我创建了一个jQuery下拉菜单,该菜单显示悬停时的div下拉菜单。

It's for a website's navigation menu, but the problem is that some menu items don't need a dropdown and I can't hide the menu for these items. 它用于网站的导航菜单,但问题是某些菜单项不需要下拉菜单,我无法隐藏这些菜单项。

Here's the JSFiddle . 这是JSFiddle What I need is for the menu item titled "No Hover" to not show the dropdown div. 我需要的是标题为“ No Hover”的菜单项,以不显示下拉div。

This is the JavaScript that I'm using: 这是我正在使用的JavaScript:

$(function () {
var $oe_menu = $('#oe_menu');
var $oe_menu_items = $oe_menu.children('li');
var $oe_overlay = $('#oe_overlay');

$oe_menu_items.bind('mouseenter', function () {
    var $this = $(this);
    $this.addClass('slided selected');
    $this.children('.hover-div').css('z-index', '9999').stop(true, true).slideDown(200, function () {
        $oe_menu_items.not('.slided').children('.hover-div').hide();
        $this.removeClass('slided');
    });
}).bind('mouseleave', function () {
    var $this = $(this);
    $this.removeClass('selected').children('.hover-div').css('z-index', '1');
});

$oe_menu.bind('mouseenter', function () {
    var $this = $(this);
    $oe_overlay.stop(true, true).fadeTo(200, 0.6);
    $this.addClass('hovered');
}).bind('mouseleave', function () {
    var $this = $(this);
    $this.removeClass('hovered');
    $oe_overlay.stop(true, true).fadeTo(200, 0);
    $oe_menu_items.children('.hover-div').hide();
})

}); });

And the HTML structure: 和HTML结构:

<div class="oe_wrapper">
<div id="oe_overlay" class="oe_overlay"></div>
<ul id="oe_menu" class="oe_menu">
    <li><a href="">Home</a>

        <div class="hover-div">Content 1</div>
    </li>
    <li><a href="">Projects</a>

        <div class="hover-div">Content 2</div>
    </li>
    <li><a href="">No Hover</a>

        <div class="hover-div">This should not appear and no other menu divs or the dark overlay should be shown.</div>
    </li>
    <li><a href="">Events</a>

        <div class="hover-div">Content 4</div>
    </li>
    <li><a href="">Stores</a>

        <div class="hover-div">Content 5</div>
    </li>
</ul>

Thanks for your help! 谢谢你的帮助! Once again, the JSFiddle is here . 再次,JSFiddle在这里

use a specific id for that item and check if it is hovered, do nothing! 使用该项目的特定ID并检查它是否悬停,什么也不做!

if($(this).attr('id', 'TheID'))
    return false;

If you add a class to the li tags and change the jquery selector, it should work : 如果您向li标签添加一个类并更改jquery选择器,则它应该可以工作:

  <li class="sub-menu">



var $oe_menu_items = $oe_menu.children('li.sub-menu');

http://jsfiddle.net/L6BEE/8/ http://jsfiddle.net/L6BEE/8/

How about add one more class for the item you don't want to show and update a few script? 如何为不想显示的项目添加一个类并更新一些脚本?

DEMO http://jsfiddle.net/L6BEE/12/ 演示http://jsfiddle.net/L6BEE/12/

CSS CSS

<div class="hover-div not-shown">
    This should not appear and no other menu divs or the dark overlay should be shown.
</div>

JQUERY JQUERY

    // updated code starts
    if($this.children('.hover-div').hasClass('not-shown')){
        $oe_menu_items.not('.slided').children('.hover-div').hide();
        $this.removeClass('slided');
    }
    else{            
        $this.children('.hover-div').css('z-index', '9999').stop(true, true).slideDown(200, function () {
            $oe_menu_items.not('.slided').children('.hover-div').hide();
            $this.removeClass('slided');
        });
    }
    // updated code ends

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

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