1

リンクの上に何度もカーソルを合わせてみてください。これにより、繰り返しのアニメーションがトリガーされます。

JQUERY//

    // Wait for the page and all the DOM to be fully loaded
$('body').ready(function() {

            // Add the 'hover' event listener to our drop down class
    $('.dropdown').hover(function() {
                    // When the event is triggered, grab the current element 'this' and
                    // find it's children '.sub_navigation' and display/hide them
        $(this).find('.sub_navigation').slideToggle(); 
    });
});

HTML//

    <ul id="navigation">
<li class="dropdown"><a href="#">Dropdown</a>
    <ul class="sub_navigation">
        <li><a href="#">Sub Navigation 1</a></li>
        <li><a href="#">Sub Navigation 2</a></li>
        <li><a href="#">Sub Navigation 3</a></li>
    </ul>
</li>
<li class="dropdown"><a href="#">Dropdown 2</a>
    <ul class="sub_navigation">
        <li><a href="#">Sub Navigation 1</a></li>
        <li><a href="#">Sub Navigation 2</a></li>
        <li><a href="#">Sub Navigation 3</a></li>
    </ul>
</li>

4

3 に答える 3

1

$('.dropdown').hover()イベントを開催する代わりに、次のようにしmouseenterてみてください。mouseexit

('.dropdown').on('mouseeneter', function() {

('.dropdown').on('mouseexit', function() {

編集

このフィドルのようなもの-Yfm5D

于 2012-10-19T01:58:34.503 に答える
0

ここで簡単なことを行うことができます: http://jsfiddle.net/gJmQh/

is(":visible")小切手。

$(this).find('.sub_navigation').is(":visible")

それがあなたの原因に合うことを願っています:)

コード

// Wait for the page and all the DOM to be fully loaded
$('body').ready(function() {

    // Add the 'hover' event listener to our drop down class
    $('.dropdown').hover(function() {
        // When the event is triggered, grab the current element 'this' and 
        if ($(this).find('.sub_navigation').is(":visible")) {
            // find it's children '.sub_navigation' and display/hide them
            $(this).find('.sub_navigation').slideUp();
        } else {
            $(this).find('.sub_navigation').slideDown();

        }

    });
});​
于 2012-10-19T02:04:05.213 に答える
0

このような

を機能させるには、2 つの関数を定義する必要があります.hover()(ホバーイン / ホバーアウト)。

$(document).ready(function() {
    $('.dropdown').hover(function() {

        $(this).find('.sub_navigation').slideDown();
    }, function() {
        $(this).find('.sub_navigation').slideUp();
    });
});
于 2012-10-19T02:06:05.147 に答える