2015-11-04 65 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

在控制台中的任何错误? –