Tema: Mover Capa
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/12/2008, 10:16
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 8 meses
Puntos: 834
Respuesta: Mover Capa

Un par de cosas:
1) El objeto debe tener posicionamiento absoluto.
2)Falta la unidad px.
3)Los condicionales se contradicen.
Probá así:
Código PHP:
<!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=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
script>
var 
avanceh=2,avancev=2;
function 
muevebola(bola) {
if( 
parseInt(bola.style.left) > 930 || parseInt(bola.style.left) <130){
    
avanceh=-avanceh
}
if( 
parseInt(bola.style.top) > 650 || parseInt(bola.style.top) <190){
avancev = -avancev;
}

bola.style.left parseInt(bola.style.left) + avanceh+'px';
bola.style.top parseInt(bola.style.top) + avancev+'px';
setTimeout(function(){muevebola(bola);}, 10);
}
onload=function(){muevebola(document.getElementById('bola'))}
</script>
</head>

<body>
<div id="bola" style="width:20px; height:20px; background-color:#F00; position:absolute; top:190px; left:130px"></div>
</body>
</html>