Foros del Web » Programando para Internet » Javascript »

[SOLUCIONADO] funcion incrementar left

Estas en el tema de funcion incrementar left en el foro de Javascript en Foros del Web. como podria hacer una funcion queincremente elvalor del left para mover de 0 (inicial) a el medio de la pagina <html> <head> <style type="text/css"> #caja{position:absolute; ...
  #1 (permalink)  
Antiguo 25/08/2013, 10:54
Avatar de nenu_racso90  
Fecha de Ingreso: diciembre-2011
Ubicación: bilbao
Mensajes: 39
Antigüedad: 12 años, 4 meses
Puntos: 0
funcion incrementar left

como podria hacer una funcion queincremente elvalor del left para mover de 0 (inicial) a el medio de la pagina
<html>
<head>
<style type="text/css">
#caja{position:absolute;
left:0%;
top:50%;
width:50px;
height:50px;
background-color:red;
}
</style>

<script>

funcion mover(){
document.GetElementById('caja').style.left =necesito el codigo k iria aqui ;
}



</script>

</head>

<body onload="mover()">

<div id="caja"></div>



</body>
</html>
__________________
_____________________________
___________DARK ELF__________
_____________________________
  #2 (permalink)  
Antiguo 25/08/2013, 12:45
 
Fecha de Ingreso: enero-2012
Ubicación: <?php echo"Los teques"; ?>/////estado miranda
Mensajes: 196
Antigüedad: 12 años, 3 meses
Puntos: 9
Respuesta: funcion incrementar left

por que usas onload?, por que no directamente lo añades al css? es algo, lamento decirlo, estupido.
añade atu css directamente
left:50%;
  #3 (permalink)  
Antiguo 25/08/2013, 13:02
Avatar de nenu_racso90  
Fecha de Ingreso: diciembre-2011
Ubicación: bilbao
Mensajes: 39
Antigüedad: 12 años, 4 meses
Puntos: 0
Respuesta: funcion incrementar left

necesito k se mueva de 0% cada segundo asta yegar a 50%
__________________
_____________________________
___________DARK ELF__________
_____________________________
  #4 (permalink)  
Antiguo 25/08/2013, 13:20
 
Fecha de Ingreso: enero-2012
Ubicación: <?php echo"Los teques"; ?>/////estado miranda
Mensajes: 196
Antigüedad: 12 años, 3 meses
Puntos: 9
Respuesta: funcion incrementar left

prueba esto a ver si te sirve
Código HTML:
Ver original
  1. <script language="JavaScript">
  2. var contador=0;
  3. function incrementar() {
  4. if(contador < 50){
  5. document.getElementById("caja").style.left= contador++ + "px";
  6. }
  7. }
  8. setInterval(incrementar(), 1000);
  9.  
  10.  
  11. </script>
  12. <style type="text/css">
  13. #caja{position:absolute;
  14. left:0%;
  15. top:50%;
  16. width:50px;
  17. height:50px;
  18. background-color:red;
  19. }
  20.  
  21. </head>
  22. <div id="caja"></div>
  23. </body>
  24. </html>
  #5 (permalink)  
Antiguo 26/08/2013, 07:14
Avatar de nenu_racso90  
Fecha de Ingreso: diciembre-2011
Ubicación: bilbao
Mensajes: 39
Antigüedad: 12 años, 4 meses
Puntos: 0
Respuesta: funcion incrementar left

Cita:
Iniciado por omarinfinito Ver Mensaje
prueba esto a ver si te sirve
Código HTML:
Ver original
  1. <script language="JavaScript">
  2. var contador=0;
  3. function incrementar() {
  4. if(contador < 50){
  5. document.getElementById("caja").style.left= contador++ + "px";
  6. }
  7. }
  8. setInterval(incrementar(), 1000);
  9.  
  10.  
  11. </script>
  12. <style type="text/css">
  13. #caja{position:absolute;
  14. left:0%;
  15. top:50%;
  16. width:50px;
  17. height:50px;
  18. background-color:red;
  19. }
  20.  
  21. </head>
  22. <div id="caja"></div>
  23. </body>
  24. </html>

nome funciona no se mueve cuando carga
__________________
_____________________________
___________DARK ELF__________
_____________________________

Etiquetas: funcion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:02.