jquery - 悬停时的巨型菜单,没有列表

标签 jquery hover slidedown slideup megamenu

我有一个大型菜单,我想在悬停时显示它并保持打开状态,直到用户离开大型菜单或触发区域。我让它在单击时工作,但我似乎无法让它在悬停时工作。任何帮助将不胜感激。

<div class="down">
    <div id="showb">
        <a href="#" id="menu-show" class="down"></a>
    </div><!-- end show button -->
    <div id="hideb">
        <a href="#" id="menu-hide" class="up"></a>
    </div><!--end hide button -->   
    <div id="menu" style="display: block;">
        <div class="menu-main">Menu Contents</div>
        <div class="menu-bottom"></div>
    </div>
</div>

    // hides the menu as soon as the DOM is ready
    // (a little sooner than page load)
    jQuery('#menu').hide();
    jQuery('#hideb').hide();
    // shows the menu on clicking the noted link
    jQuery('a#menu-show').click(function() {
        jQuery('#showb').hide();
        jQuery('#hideb').show();
        jQuery('#menu').slideDown();
        return false;
    });
    // hides the menu on clicking the noted link
    jQuery('a#menu-hide').click(function() {
        jQuery('#showb').show();
        jQuery('#hideb').hide();
        jQuery('#menu').slideUp();
        return false;
    });

你也可以在这里看到它 http://jsfiddle.net/notanothercliche/5CDEE/

<小时/>
    <div id="menu">
    <div id="show-menu">
    </div>
</div>
<div id="mega-menu">
    <div class="menu-main">Menu Contents</div>
    <div class="menu-bottom"></div>
</div>

jQuery(document).ready(function() {

    // open
    jQuery('#show-menu').bind('mouseenter', function() {

        // increase the height of our container
        jQuery('#menu').height('300px');

        // do the main animation
        jQuery('#show-menu').stop().css({
            'backgroundPosition': 'bottom'
        }, 300);
        jQuery('#mega-menu').slideDown(500);
    });


    // close
    function closeMainNav() {
        jQuery('#show-menu').stop().css({
            'backgroundPosition': 'top'
        }, 300);
        jQuery('#mega-menu').slideUp(500);
        jQuery('#menu').height('17px');
    }

    // close when the following happens
    jQuery('#menu').bind('mouseleave', closeMainNav);
});
<小时/>

对于点击版本来说,效果更好,我使用了toggleClass 和slideToggle。这样编码就短得多。请在此处查看演示 http://jsfiddle.net/notanothercliche/5CDEE/

    <a href="#" id="menu-show" class="down"></a>

<div id="menu">
    <div class="menu-main">
        Menu Contents
        <ul>
            <li>Menu Item 1</li>
            <li>Menu Item 2</li>
            <li>Menu Item 3</li>
          <div class="clear"></div>
        </ul>
        More HTML content
    </div>
    <div class="menu-bottom"></div>
</div>

jQuery(document).ready(function() {
    // hides the menu as soon as the DOM is ready
    // (a little sooner than page load)
    jQuery('#menu').hide();
    // shows the menu on clicking the noted link
    jQuery('a#menu-show').click(function() {
        // toggles the indicator arrow
        jQuery('a.down').toggleClass('up')
        jQuery('#menu').slideToggle();
        return false;
    });
});

最佳答案

为什么不做 pure CSS menu相反?

关于jquery - 悬停时的巨型菜单,没有列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6609313/

相关文章:

javascript - 关闭模态时位置标记消失

javascript - 如何在 javascript 中按空格和特殊字符拆分字符串?

css - :nth-child - Activate on Parent Hover

jQuery SlideDown 和 SlideUp 切换问题

jquery - 使用 Javascript 为元素添加样式

javascript - 原始 javascript 而不是 jquery(示例如下)

javascript - 加载 Spinner - 即使在滚动页面时也始终保持在屏幕中间

jquery - 图像悬停移动导致 X 轴溢出?

iphone - 菜单需要适合触摸屏

jquery - 如果任何其他 div 使用 jQuery 向下滑动,则 SlideUp 一个 div