2015-11-04 66 views
0

我的問題是我的孩子是絕對的位置,我必須這樣做。我無法將鼠標懸停在使用懸停功能的小孩身上,因爲它懸停在我的選擇器上。我花了幾個小時解決這個問題,但失敗了。懸停()jquery未能在我的情況下正常工作

我的代碼如下:

$(function() { 
 
    $("#hdCallUs").hover(function() { 
 
     $('.contact_numbers').show(); 
 
    }, function() { 
 
     $('.contact_numbers').hide() 
 
    }); 
 
});
ul, li { 
 
    list-style:none 
 
} 
 
#hdCallUs .call_txt { 
 
    cursor: pointer; 
 
    float:right; 
 
} 
 
#hdCallUs .contact_numbers { 
 
    display: block; 
 
    list-style: none; 
 
    position: absolute; 
 
    top: 40px; 
 
    width: 155px; 
 
    background: #fff; 
 
    right: 0; 
 
    text-align: right; 
 
    border: 1px solid #ddd; 
 
    border-top: 0; 
 
    padding: 0; 
 
} 
 
#hdCallUs .contact_numbers li { 
 
    padding: 8px; 
 
    float: none; 
 
    border-bottom: 1px solid #ddd; 
 
    cursor: pointer; 
 
} 
 
#hdCallUs .contact_numbers li:last-child { 
 
    border-bottom: 0; 
 
} 
 
#hdCallUs .contact_numbers li:hover { 
 
    background: #F9F9F9; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<li id="hdCallUs"> <span class="glyphicon glyphicon-earphone"></span> 
 
<span class="call_txt">Call Now</span> 
 

 
    <div class="contact_numbers" style="display:none"> 
 
     <ul> 
 
      <!-- added this --> 
 
      <li>999</li> 
 
      <li>888</li> 
 
     </ul> 
 
    </div> 
 
</li>

任何解決方案?

+0

'$( 「#hdCallUs,.contact_numbers」)。懸停(函數(){''_OR_ $(「#hdCallUs,#hdCallUs *「)。hover(function()' – Tushar

+0

@Tushar嘗試過,它不起作用 –

回答

0

$(function() { 
 
    $("#hdCallUs .call_txt").hover(function() { 
 
     $('.contact_numbers').show(); 
 
    }); 
 

 
$("#hdCallUs").mouseleave(function() { 
 
    $(this).find('.contact_numbers').hide(); 
 
}); 
 

 

 
});
ul, li { 
 
    list-style:none 
 
} 
 
    
 
#hdCallUs { 
 
display: inline-block; 
 
float: right; 
 
} 
 

 
#hdCallUs .call_txt { 
 
    cursor: pointer; 
 
    display: block; 
 
    text-align: right; 
 
    width: 100%; 
 

 
} 
 
#hdCallUs .contact_numbers { 
 
    display: block; 
 
    list-style: none; 
 
    top: 40px; 
 
    width: 155px; 
 
    background: #fff; 
 
    right: 0; 
 
    text-align: right; 
 
    border: 1px solid #ddd; 
 
    border-top: 0; 
 
    padding: 0; 
 
} 
 
#hdCallUs .contact_numbers li { 
 
    padding: 8px; 
 
    float: none; 
 
    border-bottom: 1px solid #ddd; 
 
    cursor: pointer; 
 
} 
 
#hdCallUs .contact_numbers li:last-child { 
 
    border-bottom: 0; 
 
} 
 
#hdCallUs .contact_numbers li:hover { 
 
    background: #F9F9F9; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<li id="hdCallUs"> <span class="glyphicon glyphicon-earphone"></span> 
 
<span class="call_txt">Call Now</span> 
 

 
    <div class="contact_numbers" style="display:none"> 
 
     <ul> 
 
      <!-- added this --> 
 
      <li>999</li> 
 
      <li>888</li> 
 
     </ul> 
 
    </div> 
 
</li>

+0

如果你現在徘徊打電話並懸停離開,孩子不會隱藏。 –

+0

現在試試吧,float right是擰高了SO代碼中的「全頁」按鈕vi ew將鼠標移出「hdCallUs」div之外 - 這不應該成爲您自己網站的問題。 –

+0

哪一行更改? –

0

試試這個

$("#hdCallUs").hover(function(){ 
    $('.contact_numbers').show(); 
}).mouseleave(function(){ 
    $('.contact_numbers').hide(); 
}); 
+0

nope它不起作用 –

+0

在控制檯中的任何錯誤? –