2011-05-06 7 views
0

("ul.topnav li")がホバーされていて、<span>が表示されていないときにメニューがドロップするように、このコードを変更するにはどうすればよいですか?私がコードを変更したときには、("ul.subnav)が上に乗ったときに全てが落ちました。jqueryドロップダウンメニュー

おかげで、あなたはliから.mouseenter()イベントの添付ファイルを変更すると

<script language="javascript" type="text/javascript"> 
    $(document).ready(function() { 

     $("ul.subnav").parent().append("<span></span>"); 

     //When trigger is clicked... 
     $("ul.topnav li span").mouseenter(function() { 

      //Following events are applied to the subnav itself 
      //(moving subnav up and down) 

      //Drop down the subnav on click 
      $(this).parent().find("ul.subnav").slideDown('fast').show(); 

      $(this).parent().hover(function() { 
      }, function() { 
       //When the mouse hovers out of the subnav, move it back up 
       $(this).parent().find("ul.subnav").slideUp('slow'); 
      }); 

     //Following events are applied to the trigger 

     }).hover(function() { //(Hover events for the trigger) 

      $(this).addClass("subhover"); //On hover over, add class "subhover" 
     }, function() { //On Hover Out 

      //On hover out, remove class "subhover" 
      $(this).removeClass("subhover"); 
     }); 

    }); 


</script> 
+0

私は(あなたがthis.slidetoggleを下にスライドさせるサブたNAVのすべてをスライドさULのNAVの親を選択していると思います) –

答えて

2

、それは関数内のすべての範囲を変更します。幸いにも、その中のすべてのコードは、元々ターゲティングしていたspanの親liに戻ろうとします。だから、これを修正する。適切な場合はparent()への呼び出しを削除するだけです。

<script language="javascript" type="text/javascript"> 
    $(document).ready(function() { 

     $("ul.subnav").parent().append("<span></span>"); 

     //When trigger is clicked... 
     $("ul.topnav li").mouseenter(function() { 

      //Following events are applied to the subnav itself 
      //(moving subnav up and down) 

      //Drop down the subnav on click 
      $(this).find("ul.subnav").slideDown('fast').show(); 

      $(this).parent().hover(function() {}, 
      function() { 
       //When the mouse hovers out of the subnav, move it back up 
       $(this).find("ul.subnav").slideUp('slow'); 
      }); 

     //Following events are applied to the trigger 

     }).hover(function() { //(Hover events for the trigger) 

      $(this).addClass("subhover"); //On hover over, add class "subhover" 
     }, function() { //On Hover Out 

      //On hover out, remove class "subhover" 
      $(this).removeClass("subhover"); 
     }); 

    }); 
</script> 
+0

私はすでにえっ...しかし、私は私が右そうだったと思うとコメント –

+0

あなたのコメントを見ませんでした\:受け入れられた回答としてコメントをマークすることはできませんので、この質問は答えなしで "閉鎖"されることはありません\: –

+0

私は私の答えを確信していませんでしたあなたはそれに答えました。私はちょうど半分の答えを "答え"に入れたくない。 –

関連する問題