1

How can I delay addClass in jQuery? I tried but it doesn't work:

$(document).ready(function(){
  $(".box1").delay(600).addClass("animated bounce");
});

Thank you in advance!

dda
  • 6,030
  • 2
  • 25
  • 34
R. Catalin
  • 25
  • 4

1 Answers1

1

The jQuery delay() method helps to provide a delay between animation queue. In your case, you need to use setTimeout method.

$(document).ready(function(){
  setTimeout(function(){ 
    $(".box1").addClass("animated bounce"); 
  },600)
});

$(document).ready(function() {
  setTimeout(function() {
    $(".box1").addClass("animated bounce");
  }, 600)
});
.box1,
.box2 {
  width: 300px;
  height: 200px;
  margin-bottom: 100px;
  margin-left: 100px;
  background-color: #62a6c9;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box1"></div>
<div class="box2"></div>
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188