Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

79
Vistas
How to correctly format transform

  var kidX = "";
    
    if(kidX == ""){
    kidX = 100;
    }
    
    
    document.addEventListener('keydown', function(event) {
    if(event.keyCode == 37) {
        kidX--;


    document.getElementById("kid").style.transform = "translateX(kidX + "px")";
    
       console.log(document.getElementById("kid").style.transform);

  
    }
    else if(event.keyCode == 39) {
    kidX++;
    document.getElementById("kid").style.transform = "translateX(kidX + "px")";
       // console.log(kidX + "px");
       console.log(document.getElementById("kid").style.transform);
    }
});
<!DOCTYPE html> 

<html>
  <head>
  
   
    
  </head>
  <style>
 img{
    height = 100px;
    }
   
    .guy{
    height = 100px;
    
    }
    div{
     height = 100px;
    }
    
</style>
  <body id="body">
    
  <p  >
            <div id="kid">
<img class = "guy" src="kid.png" alt="kid!" height = "100px"  />
<p>
 hello
</p>
              
</div>
            
    
    <p>
 
 

    
 </body></html>

Hello. I want to make the element kid move with the arrow keys, but I think I am formatting it wrong. Can someone tell me how to format it correctly, thanks. If there is a better way to make the element kid move left and right please tell me. I am new to JavaScript and html so any help is appreciated .

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda