Jump to content

Ajuda com setTimeout dentro das functions


CDanielOL
 Share

Recommended Posts

Agradecia que alguém desse uma olhada no código abaixo e me explicasse porque cada vez que "completa um ciclo inteiro" a velocidade vai aumentando cada vez mais.  :wallbash:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<STYLE type="text/css">
<!-- 
body{ 
	background-attachment:fixed;
	background-color: #333333;
	background-image:url(fundo.gif);
	background-repeat:no-repeat;
	background-position:left top;
}
-->
</STYLE>
</head>

<body bgcolor="#333333" style="cursor: url(mira.cur)" onload="gerar();">
<script>
var px=0;
var py=0;
var x,y,timer;
function gerar(){
		y=410;
		px=Math.floor(Math.random()*900);
		document.getElementById('coelho').style.left=px +'px';
		document.getElementById('coelho').style.top=410 +'px';
		movimenta();
}
function movimenta()
	{
			y-=2;
			document.getElementById('coelho').style.top=y +'px';
			timer=setTimeout('movimenta()',70);
			if(y<350){
				gerar();
			}
	}
</script>
<img src="coelho2.png" style="position:absolute;" id="coelho" />
    <img src="arvores.png" style="position:absolute;top:313px;left:0px" id="arvore" />
</body>
</html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.