0

Why doesn't this hover Animate.css animation work after the initial page load animation?

$(document).ready(function(){

$("h1").addClass("animated zoomInDown")

$("h1").hover(function(){
$(this).addClass('animated shake');

});

1 Answer 1

2

If you're using hover() make sure you have handlers for both hover-in and hover-out events. CSS animation will only re-run if it's removed then added again:

$(document).ready(function() {

  $("h1").addClass("animated zoomInDown")

  $("h1").hover(function() {
    $(this).addClass('animated shake');
  }, function() {
    $(this).removeClass('animated shake');
  });
});
h1 {
  background: yellow;
  position: relative;
}

.animated {
  animation: animate-color 0.2s linear;
  animation-iteration-count: 5;
}

@keyframes animate-color {
  0% {
    left: 0;
  }
  50% {
    left: 5px;
    background: red;
  }
  100% {
    left: 0px;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Hello</h1>

Sign up to request clarification or add additional context in comments.

2 Comments

This is partially correct however it doesn't have the $("h1").addClass("animated zoomInDown") animation when the page is loaded @AVAVT
@user3519870 can you provide your environment (browser/device)? I'm testing on both Chrome and Firefox here and the animation's running well the first time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.