How to repeat animation in jquery

Many times in web designing we want to <strong>repeat animation in jquery</strong>. We can animate jquery animations by infinite times, here is the quick example for doing this.

by Nikhil Mangal

HTML

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<div id="rectangle"></div>

CSS

#rectangle
{
	width:100px;
	height:100px;
	background:#00CC66;
}

JavaScript

$(document).ready(function(e) {
	function resetAnimation(){
		$('#rectangle').animate({"marginLeft":"0px"},1500);
		}
	function animateRect(){
    $('#rectangle').animate({"marginLeft":"100px"},1500,function(){
		resetAnimation();
		animateRect();
		});
	}
	animateRect();
});