jQuery Animation How to - Repeat animation








Question

We would like to know how to repeat animation.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(document).ready(function(){<!--from  ww w .  jav a2  s .co  m-->
   setInterval(callMe,2000);
});
function callMe(){
   $("div").animate({left:'250px'}).fadeOut().animate({left:'0'}).fadeIn();
}

</script>
</head>
<body>
  <button>Start Animation</button>
  <br />
  <br />
  <div
    style="background: #98bf21; height: 100px; width: 100px; position: absolute;">
  </div>
</body>
</html>

The code above is rendered as follows: