1

クリックするとスライドが開くこのバーを作成しました。ただし、+がクリックされたときにのみ開きたいです。+ハイパーリンクがありますが、スライダーを+にのみ応答させ、サイドバーを通常に戻す方法がわかりません(現在、コンテンツdivの下に移動しています。助けてください。

    <!DOCTYPE HTML>

<html>
    <head>
        <title>Title</title>
        <link rel="stylesheet" href="style.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">   </script>
    </head>

    <body>

    <div id="wrapper">
        <div id="nav">
        <div id="menu-expand">
        <a href="#" class="closed"><span>+</span></a>
        </div>
        </div>
            <div id="content"></div>
    </div>

    <!-- Scripts -->

<script>
    $(function() {
    $('#nav').click(function() {
        var leftMargin = ($(this).css('margin-left') === '0px') ? '-150px' : '0px';
        $(this).animate({ 'margin-left' : leftMargin }, 500);
    });
});

</script>
    </body>
</html>
4

1 に答える 1

0

クリックイベント「バブル」がDOMを介して発生し、以下を使用しない限りev.stopPropagation()、すべての親要素で発生します。

$('#nav').click(function(ev) {
    ev.stopPropagation();
    var leftMargin = ($(this).css('margin-left') === '0px') ? '-150px' : '0px';
    $(this).animate({ 'margin-left' : leftMargin }, 500);
});
于 2012-08-13T19:13:24.620 に答える