JS Interval


html file

<!DOCTYPE html>
<html lang="en">
<head>
	<title>JavaScript Animation</title>
	<style>
		#test{
			width:150px;
			height:150px;
			background: red;
		}
	</style>
</head>
<body>
	<div id="test"></div>
	<script src="js/animation.js"></script>
</body>
</html>

 
animation.js


var a = 0;
var id = setInterval(Anim,500);

function Anim(){
	a = a + 10;
	if(a == 200){
		clearInterval(id);
	}else{
		var target = document.getElementById("test");
		//target.style.marginLeft = a + 'px';
		target.style.width = a + 'px';
	}
}