2

ホバー時に表示し、ユーザーがメガメニューまたはトリガー領域を離れるまで開いたままにしたいこのメガメニューがあります。onClickで動作していますが、ホバーで動作させることができないようです。どんな助けでも大歓迎です。

<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;
    });
});
4

2 に答える 2

1

代わりに、純粋な CSS メニューを作成してみませんか?

于 2011-07-07T10:43:09.613 に答える
0

ソリューションの問題は、html と css の配置方法です。ここで調整を行いました

http://jsfiddle.net/nTskw/

これはアップボタンを隠しませんが、代わりにクラスを交換します。アニメーションとの間に少し作業の必要なギャップがありますが、これはまだ要素の配置にかかっていると思います。周囲のdivにマウスオーバーをバインドする価値があるかもしれません

于 2011-07-07T10:47:12.733 に答える