Jquery悬停slideDown和fadeOut

时间:2015-11-30 10:30:43

标签: jquery html mouseout

代码上的css工作正常,但jquery函数不能正常工作我只需要鼠标悬停在div上,div中的隐藏div应该是slideDown,当它离开时应该是fadeOut。

<div class="col-md-12 services-content">
   <div class="services-pannel">
       <div class="services-in">
           <div class="services-hov">Learn More</div>
           <p> <img class="padtp" src="services-preventative.png"></p>
           <h4>PREVANTATIVE</h4>
           <p>
               Lorem ipsum dolor consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore .
           </p>
           <p></p>
       </div>
   </div>
   <div class="services-pannel">
       <div class="services-in">
           <div class="services-hov">Learn More</div>
           <p> <img class="padtp" src="services-restorative.png"></p>
           <h4>RESTORATIVE</h4>
           <p>
               Lorem ipsum dolor consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore .
           </p>
           <p></p>
       </div>
   </div>
</div>

这是css

.services-pannel{
    display:inline-block;
    width:225px;
    text-align:center;
    background-color:#a8d9e9;
    margin: 1px -1px;
    position: relative;
    height: 185px;
}
.services-in{
  position: absolute;
  width: 225px;
  height: 185px;
  cursor: pointer;
}
.padtp{padding-top: 20px;}
.services-hov{
  position: absolute;
  display: none;
  text-align: center;
  width: 225px;
  height: 185px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  text-decoration: none;
  padding-top: 88px;
}
.services-section-heading{
    color:#333;
    text-align:center;  
    margin-bottom:40px;
    font-size:24px;
    color:#666;
}
.heading-line-services{
    color:#666; 
}
.services-pannel p{
    font-size:0.8em;
    padding:0 20px;
}
.services-pannel h4{
    font-size:bold  ;
    color:#333;
}

和jquery

$(function(){
    $(".services-in").mouseover(function() {
        $(".services-hov").slideDown(400);
    });
    $(".services-hov").mouseout(function() {
        $(".services-hov").fadeOut(400);
    });
});

Jsfiddle

2 个答案:

答案 0 :(得分:1)

请在JS Fiddle中添加jquery版本&#34; Frameworks&amp;扩展&#34 ;.你的代码工作正常。

答案 1 :(得分:1)

试试这个

&#13;
&#13;
$(function() {
  $(".services-in").mouseover(function(e) {
    $(this).children(".services-hov").slideDown(100);
  });
  $(".services-hov").mouseout(function(e) {
    $(".services-hov").fadeOut(500);
  });
});
&#13;
.services-pannel {
  display: inline-block;
  width: 225px;
  text-align: center;
  background-color: #a8d9e9;
  margin: 1px -1px;
  position: relative;
  height: 185px;
}
.services-in {
  position: absolute;
  width: 225px;
  height: 185px;
  cursor: pointer;
}
.padtp {
  padding-top: 20px;
}
.services-hov {
  position: absolute;
  display: none;
  text-align: center;
  width: 225px;
  height: 185px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  text-decoration: none;
  padding-top: 88px;
}
.services-section-heading {
  color: #333;
  text-align: center;
  margin-bottom: 40px;
  font-size: 24px;
  color: #666;
}
.heading-line-services {
  color: #666;
}
.services-pannel p {
  font-size: 0.8em;
  padding: 0 20px;
}
.services-pannel h4 {
  font-size: bold;
  color: #333;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12 services-content">
  <div class="services-pannel">
    <div class="services-in">
      <div class="services-hov">Learn More</div>
      <p>
        <img class="padtp" src="services-preventative.png">
      </p>
      <h4>PREVANTATIVE</h4>

      <p>Lorem ipsum dolor consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore .</p>
      <p></p>
    </div>
  </div>
  <div class="services-pannel">
    <div class="services-in">
      <div class="services-hov">Learn More</div>
      <p>
        <img class="padtp" src="services-restorative.png">
      </p>

      <h4>RESTORATIVE</h4>

      <p>Lorem ipsum dolor consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore .</p>
      <p></p>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;