2016-10-20 4 views
0

最初は本当にすみません。私は新しいユーザーです。ドロップダウンの内容が自動的に表示され、jqueryを使用してそれを表示します。

私は私に同じ問題を見つけることはできません。

誰でも私になぜnavbarドロップダウンボタンが突然表示されているのかを教えてもらえます。

私は人々が理解できないことを知っています。これは私の問題です。

$(document).ready(function(){ 
 
\t $('.menubar ul li').hover(function(){ 
 
\t $(this).find('.dropdown-content').slideToggle(400); 
 
\t }); 
 
});
ol, ul { 
 
    margin-top: 0; 
 
    margin-bottom: 10px; 
 
    display: inline-block; 
 
    list-style-type: none; 
 
} 
 

 
div { 
 
\t 
 
\t display:block; 
 
} 
 

 
center { 
 
\t display: block; 
 
    text-align: -webkit-center; 
 
} 
 

 
.clearfix:after { 
 
    display:block; 
 
    clear:both; 
 
\t 
 

 
} 
 

 
.menubar { 
 
    width:1100px; 
 
\t height:50px; 
 
\t text-align:center; 
 
\t background-color:#454545; 
 
\t margin-left:auto; 
 
\t margin-right:auto; 
 
    list-style-type: none; 
 
} 
 

 
.menu { 
 
    width:100%; 
 
\t text-decoration:none; 
 
\t 
 
} 
 

 
    
 
.menu li { 
 

 
\t float:center; 
 
\t display:inline; 
 
    list-style:none; 
 
    font-family:"Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; 
 
    font-weight:normal; 
 
    font-style:normal; 
 
} 
 
    
 
.menu li.shoppingcart \t { 
 
\t background:url("images/shoppingcart.png"); 
 
\t width:61px; 
 
} 
 
    
 
.menu a { 
 
    transition:all linear 0.2s; 
 
    color:white; 
 
\t font-size:15px; 
 
\t font-weight:normal; 
 
\t font-style:normal; 
 
} 
 
    
 
.menu li:hover > a, .menu .current-item > a { 
 
    color:#aa79da; 
 
\t height:100%; 
 
\t cursor:pointer; \t 
 
\t text-shadow: 0 0 10px purple; 
 
\t background-color:#4c4b4b; \t 
 
} 
 

 
.menu > ul > li { 
 
    margin-left:auto; 
 
\t margin-right:auto; 
 
    text-align: center; 
 
    display: inline-block; 
 
    position: relative; 
 
    text-decoration: none; 
 
\t 
 
} 
 

 
.menu > ul > li > a { 
 
    padding: 30px 30px; 
 
    padding-top: 18px; 
 
    padding-bottom: 10px; 
 
    display: inline-block; 
 
    text-shadow: 0px 1px 0px rgba(0,0,0,0.4); 
 
    text-decoration: none; 
 
\t margin-top: 0px; 
 

 

 
} 
 

 

 

 
-------------------------------------------------------------- 
 

 

 

 
ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: #333; 
 
\t display: inline-block; 
 
    list-style-type: none; \t 
 
\t 
 
} 
 

 
li { 
 
    float: left; 
 
} 
 

 
li a, .dropbtn { 
 
    display: inline-block; 
 
    color: white; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
} 
 

 
li a:hover, .dropdown:hover .dropbtn { 
 
    /*background-color: red;*/ 
 
} 
 

 

 
.activeNav { 
 
\t background-color:#5e4279; 
 
\t 
 
} 
 

 
.activeNav a{ 
 
\t color:white; 
 
\t font-weight:bold; 
 
\t 
 
} 
 

 
.activeNav li:hover > a, .activeNav .current-item > a { 
 
\t /*background-color: #707070;*/ 
 
\t text-decoration:none; 
 
\t color:white; 
 
\t font-weight:bold; 
 
} 
 

 
li.dropdown { 
 
    display: inline-block; 
 
} 
 

 
.dropdown-content { 
 
\t /*margin-top:6px;*/ 
 
\t /*width: 100%;*/ 
 
    display: none; 
 
    position: absolute; 
 
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 
 
\t width:auto; 
 
\t background-color:#4c4b4b; 
 
\t z-index:100; 
 
\t 
 

 
\t 
 
} 
 

 

 

 
.dropdown1 { 
 
\t margin-top:0px; 
 
\t width:200px; 
 
\t background-color:#4c4b4b; 
 
\t float:left; 
 

 
} 
 
.dropdown2 { 
 
\t width:200px; 
 
\t background-color:#4c4b4b; 
 
\t margin-left:200px; 
 
\t float:center; 
 
} 
 
.dropdown3 { 
 
\t width:200px; 
 
\t background-color:#4c4b4b; 
 
\t float:right; \t 
 
\t margin-left:400px; 
 
\t margin-top:-269px; 
 
} 
 

 
.dropdown-content a { 
 
    color: white; \t 
 
    padding: 12px 16px; 
 
    text-decoration: none; 
 
    display: block; 
 
\t font-size:12px; 
 
    text-align: center; 
 
\t text-decoration:none; 
 
\t 
 
} 
 

 
.dropdown-content a:hover { 
 
\t /*background-color: #707070;*/ 
 
\t text-decoration:none; 
 
\t text-shadow: 0 0 10px purple; 
 
\t color:#aa79da; 
 
\t font-weight:bold; 
 

 
} 
 

 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="menubar"> 
 
\t \t <nav class="menu"> 
 
\t \t \t <ul class="clearfix"> 
 
\t \t \t \t <li class="activeNav"><a class="home" href="home.php">Home</a></li> 
 
\t \t \t \t <li class="dropdown"><a class="dropbtn" title="Discover KTD"><span class="menu-title">Discover KTD</span></a> 
 
\t \t \t \t \t <div class="dropdown-content"> 
 
\t \t \t \t \t \t \t <div class="dropdown1"> 
 
\t \t \t \t \t \t \t \t <h4 style="margin-top:0px; padding-top:35px; color:white; text-shadow: 0px 1px 0px rgba(0,0,0,0.4); font-family:Helvetica Neue , Helvetica, Helvetica, Arial, sans-serif; text-decoration: underline;">WHY KTD?</h4> 
 
\t \t \t \t \t \t \t \t <a href="#">Message from CEO</a> 
 
\t \t \t \t \t \t \t \t <a href="#">Overview of KTD</a> 
 
\t \t \t \t \t \t \t \t <a href="#">Vision & Mission</a> 
 
\t \t \t \t \t \t \t \t <a href="#">Philosophy & Core Values</a> 
 
\t \t \t \t \t \t \t \t <a href="#">Testimonials</a> 
 
\t \t \t \t \t \t \t \t <a href="#">KTD Partners</a> 
 
\t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t <div class="dropdown2"> 
 
\t \t \t \t \t \t \t \t <h4 style="margin-top:0px; padding-top:35px; color:white; text-shadow: 0px 1px 0px rgba(0,0,0,0.4); font-family:Helvetica Neue , Helvetica, Helvetica, Arial, sans-serif; text-decoration: underline;">KTD Leadership</h4> 
 
\t \t \t \t \t \t \t \t <a href="#">Board of Directors</a> 
 
\t \t \t \t \t \t \t \t <a href="#">Key Management Team</a> 
 
\t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </li> 
 
\t \t \t </ul> 
 
\t \t </nav> 
 
\t </div>

答えて

0

私はこのコードをテストしていません、しかし、あなたは、この問題が発生しないかどうかを確認するmouseovermouseoutを使用して試すことができますか?

$(document).ready(function(){ 
    $('.menubar ul li.dropdown').mouseover(function(){ 
    $(this).find('.dropdown-content').slideDown(400); 
    }).mouseout(function(){ 
    $(this).find('.dropdown-content').slideUp(400); 
    }); 
}); 
+0

それは仕事をdidntの、そしてそれがオープンドロップダウンとに常時自体近くのようなものです。私を助けてくれてありがとう。 –

0

希望します。

$(document).ready(function() { 
 
    $('.menubar ul li').mouseleave(function() { 
 
    $(this).find('.dropdown-content').slideUp(4000); 
 
    }); 
 
});
ol, 
 
ul { 
 
    margin-top: 0; 
 
    margin-bottom: 10px; 
 
    display: inline-block; 
 
    list-style-type: none; 
 
} 
 
div { 
 
    display: block; 
 
} 
 
center { 
 
    display: block; 
 
    text-align: -webkit-center; 
 
} 
 
.clearfix:after { 
 
    display: block; 
 
    clear: both; 
 
} 
 
.menubar { 
 
    width: 1100px; 
 
    height: 50px; 
 
    text-align: center; 
 
    background-color: #454545; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    list-style-type: none; 
 
} 
 
.menu { 
 
    width: 100%; 
 
    text-decoration: none; 
 
} 
 
.menu li { 
 
    float: center; 
 
    display: inline; 
 
    list-style: none; 
 
    font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; 
 
    font-weight: normal; 
 
    font-style: normal; 
 
} 
 
.menu li.shoppingcart { 
 
    background: url("images/shoppingcart.png"); 
 
    width: 61px; 
 
} 
 
.menu a { 
 
    transition: all linear 0.2s; 
 
    color: white; 
 
    font-size: 15px; 
 
    font-weight: normal; 
 
    font-style: normal; 
 
} 
 
.menu li:hover > a, 
 
.menu .current-item > a { 
 
    color: #aa79da; 
 
    height: 100%; 
 
    cursor: pointer; 
 
    text-shadow: 0 0 10px purple; 
 
    background-color: #4c4b4b; 
 
} 
 
.menu > ul > li { 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    text-align: center; 
 
    display: inline-block; 
 
    position: relative; 
 
    text-decoration: none; 
 
} 
 
.menu > ul > li > a { 
 
    padding: 30px 30px; 
 
    padding-top: 18px; 
 
    padding-bottom: 10px; 
 
    display: inline-block; 
 
    text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.4); 
 
    text-decoration: none; 
 
    margin-top: 0px; 
 
} 
 
-------------------------------------------------------------- ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: #333; 
 
    display: inline-block; 
 
    list-style-type: none; 
 
} 
 
li { 
 
    float: left; 
 
} 
 
li a, 
 
.dropbtn { 
 
    display: inline-block; 
 
    color: white; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
} 
 
li a:hover, 
 
.dropdown:hover .dropbtn { 
 
    /*background-color: red;*/ 
 
} 
 
.activeNav { 
 
    background-color: #5e4279; 
 
} 
 
.activeNav a { 
 
    color: white; 
 
    font-weight: bold; 
 
} 
 
.activeNav li:hover > a, 
 
.activeNav .current-item > a { 
 
    /*background-color: #707070;*/ 
 
    text-decoration: none; 
 
    color: white; 
 
    font-weight: bold; 
 
} 
 
li.dropdown { 
 
    display: inline-block; 
 
} 
 
.dropdown-content { 
 
    /*margin-top:6px;*/ 
 
    /*width: 100%;*/ 
 
    display: none; 
 
    position: absolute; 
 
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); 
 
    width: auto; 
 
    background-color: #4c4b4b; 
 
    z-index: 100; 
 
} 
 
.dropdown1 { 
 
    margin-top: 0px; 
 
    width: 200px; 
 
    background-color: #4c4b4b; 
 
    float: left; 
 
} 
 
.dropdown2 { 
 
    width: 200px; 
 
    background-color: #4c4b4b; 
 
    margin-left: 200px; 
 
    float: center; 
 
} 
 
.dropdown3 { 
 
    width: 200px; 
 
    background-color: #4c4b4b; 
 
    float: right; 
 
    margin-left: 400px; 
 
    margin-top: -269px; 
 
} 
 
.dropdown-content a { 
 
    color: white; 
 
    padding: 12px 16px; 
 
    text-decoration: none; 
 
    display: block; 
 
    font-size: 12px; 
 
    text-align: center; 
 
    text-decoration: none; 
 
} 
 
.dropdown-content a:hover { 
 
    /*background-color: #707070;*/ 
 
    text-decoration: none; 
 
    text-shadow: 0 0 10px purple; 
 
    color: #aa79da; 
 
    font-weight: bold; 
 
} 
 
.dropdown:hover .dropdown-content { 
 
    display: block!important; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="menubar"> 
 
    <nav class="menu"> 
 
    <ul class="clearfix"> 
 
     <li class="activeNav"><a class="home" href="home.php">Home</a> 
 
     </li> 
 
     <li class="dropdown"><a class="dropbtn" title="Discover KTD"><span class="menu-title">Discover KTD</span></a> 
 
     <div class="dropdown-content"> 
 
      <div class="dropdown1"> 
 
      <h4 style="margin-top:0px; padding-top:35px; color:white; text-shadow: 0px 1px 0px rgba(0,0,0,0.4); font-family:Helvetica Neue , Helvetica, Helvetica, Arial, sans-serif; text-decoration: underline;">WHY KTD?</h4> 
 
      <a href="#">Message from CEO</a> 
 
      <a href="#">Overview of KTD</a> 
 
      <a href="#">Vision & Mission</a> 
 
      <a href="#">Philosophy & Core Values</a> 
 
      <a href="#">Testimonials</a> 
 
      <a href="#">KTD Partners</a> 
 
      </div> 
 
      <div class="dropdown2"> 
 
      <h4 style="margin-top:0px; padding-top:35px; color:white; text-shadow: 0px 1px 0px rgba(0,0,0,0.4); font-family:Helvetica Neue , Helvetica, Helvetica, Arial, sans-serif; text-decoration: underline;">KTD Leadership</h4> 
 
      <a href="#">Board of Directors</a> 
 
      <a href="#">Key Management Team</a> 
 
      </div> 
 
     </div> 
 
     </li> 
 
    </ul> 
 
    </nav> 
 
</div>

+0

私は実際に欲しいものは、私はちょうどslideToggleのようなjqueryの機能を持つドロップダウンメニューを持って、私はいくつかのチュートリアルに従っていますが、それは私のために動作しません。これは最終的な結果です。これは、最初の時間に移動したときにドロップダウンメニューが表示され、それ自体で非表示になります。その後、ドロップダウンメニューが表示されます。私はちょうど私がそれをホバーするときにそれが欲しいです。私は主な問題が何であるか分かりません。とにかく再び仲間に感謝します。 –

+0

@HappyLittleMaskBoy:デフォルト状態のドロップダウンメニューを開いて、ホバー機能が正常に動作するように設定しました。 – masif

関連する問題