Aide animation div javascript

Bonjour, j'essaye de faire bouger mon div au cliquage du bouton input mais celui ci ne bouge pas.

Si je met la variable idTimer dans le body avec pour action onLoad l'animation se fait.

Si quelqu'un pourrai m'aider.

Merci

Script ne marchant pas :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<link rel="stylesheet" media="screen" type="text/css" title="styles" href="css.css" />
</head>
<body>
	
<style>

#carre {
	background-color: red;
	height: 50px;
	width:  50px;	
}

</style>	
	
<script type="text/javascript">

	var cursor = 0;

	function move() {
		
		var carre = document.getElementById("carre");
		
		carre.style.marginLeft = 5*cursor + "px";
		
		if (cursor > 50)
			clearInterval(idTimer);
		else
			cursor++;
	}
	
</script>

<div id="carre"></div>

<br/>
<br/>

<input type="button" value="Clique" onClik="idTimer = setInterval('move()', 20);"/>
		
</body>
</html>


Script qui marche

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<link rel="stylesheet" media="screen" type="text/css" title="styles" href="css.css" />
</head>
<body onload = "idTimer = setInterval('move()',20);">
	
<style>

#carre {
	background-color: red;
	height: 50px;
	width:  50px;	
}

</style>	
	
<script type="text/javascript">

	var cursor = 0;

	function move() {
		
		var carre = document.getElementById("carre");
		
		carre.style.marginLeft = 5*cursor + "px";
		
		if (cursor > 50)
			clearInterval(idTimer);
		else
			cursor++;
	}
	
</script>

<div id="carre"></div>
		
</body>
</html>
Configuration: Mac OS X
Firefox 3.0

1 réponse

  1. C'est bizarre que personne t'ai repondu avant Oo
    mais voila ta toute petite erreur ^^
    <input type="button" value="Clique" onClik="idTimer = setInterval('move()', 20);"/>
    c'est "onclick" et non "onclik" ^^
    2