Aide animation div javascript

Fermé
luffy59 - 28 juin 2008 à 16:07
Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 - 9 oct. 2008 à 22:13
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>
A voir également:

1 réponse

Brachior Messages postés 613 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 22 juin 2009 46
9 oct. 2008 à 22:13
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