Androbaut Androbaut - 1 month ago 25
CSS Question

Add animate.css class on mouseenter & mouseleave

I'd like to use animate.css to fadeIn/fadeOut content when the user hovers over a image.



I'm trying to figure out the best way to switch classes from 'FadeIn' & 'FadeInUp' on mouseenter to 'FadeOut' & 'FadeOutDown' on mouseleave.

Codepen Example

CSS



.overlay{
position: absolute;
top: 0;
height: 100%;
width: 100%;
background: rgba(40,40,40,0.88);
left: 0;
padding: 10px;
text-align: left;
display: none;
}
.col-sm-6:hover .overlay{
display: block;
}
.overlay h2{
font-size: 20px;
color: #fff;
}
.overlay p{
color: #bbbbbb;
}
.linkbox{
position: absolute;
height: 50px;
bottom: 0;
left: 0;
background: #000;
width: 100%;
padding: 16px;
text-align: left;
color: #fff;
}
.caption{
display: none;
}


Any help/advice/suggestions will be appreciated!

Answer

try this script:

$('.col-sm-6').on('mouseenter', function(){
  $('.overlay').addClass('fadeIn fadeInUp');
  $('.overlay').removeClass('fadeOut fadeOutDown');
  $('.overlay').css('display', 'block');
});

$('.col-sm-6').on('mouseleave', function(){
  $('.overlay').removeClass('fadeIn fadeInUp');
  $('.overlay').addClass('fadeOut fadeOutDown');
  $('.overlay').css('display', 'block');
  setTimeout(function(){
     $('.overlay').css('display', 'none');
  }, 1000);
});