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

194
Vistas
¿Cuál es el ancho de un solo carácter?

Estoy creando un cuadro de entrada falso para poder aplicar un cursor de texto de estilo antiguo como cmd _ .

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function copy(val){ $(".copy").html(val); $(".vintage").css("left",val.length*1.5+"ch");} function enterCmd(e){ if(event.keyCode==13){ $('.cmdBox').val(""); copy($('.cmdBox').val());}} </script> <!--So as the length of the string increases the cursor should move back and forth respectively. But it starts out accurately and then drifts away--> <div class="cmdBoxy" >&gt;<span class="copy" ></span> <div class="vintage blink"></div> </div> <input type="text" class="cmdBox" oninput="copy($('.cmdBox').val());" id="lp" onkeydown="enterCmd($('.cmdBox'))"> <style> .vintage{ position:relative; background-color:white; height:25%; width:2%; left:1.5%; font-size:1em;} .cmdBoxy{ position:relative; top:1rem; background-color:red; height:1.5rem; width:99%;} </style>

¿Cómo hago para que el cursor se mueva sincronizado con el texto?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Una solución simple sería usar una fuente monoespaciada, donde el ancho de todos los caracteres es el mismo. Un ejemplo sería Courier New .

Entonces solo puedes usar:

 $(".vintage").css("left",val.length*1+"ch");}

Puedes ver un fragmento aquí:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function copy(val){ $(".copy").html(val); $(".vintage").css("left",val.length*1+"ch");} function enterCmd(e){ if(event.keyCode==13){ $('.cmdBox').val(""); copy($('.cmdBox').val());}} </script> <!--So as the length of the string increases the cursor should move back and forth respectively. But it starts out accurately and then drifts away--> <div class="cmdBoxy" >&gt;<span class="copy" ></span> <div class="vintage blink"></div> </div> <input type="text" class="cmdBox" oninput="copy($('.cmdBox').val());" id="lp" onkeydown="enterCmd($('.cmdBox'))"> <style> * { font-family: 'Courier New'; } .vintage{ position:relative; background-color:white; height:25%; width:2%; left:1.5%; font-size:1em;} .cmdBoxy{ position:relative; top:1rem; background-color:red; height:1.5rem; width:99%;} </style>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Esto debería funcionar perfectamente para usted, coincide y solucioné un error que cometió en el CSS (una "y" perdida). Acabo de hacer coincidir las fuentes y ajusté el relleno dentro del cuadro de entrada para alinearlo.

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function copy(val){ $(".copy").html(val); $(".vintage").css("left",val.length*1.5+"ch"); } function enterCmd(e){ if(event.keyCode==13) { $('.cmdBox').val(""); copy($('.cmdBox').val()); } } </script> <!--So as the length of the string increases the cursor should move back and forth respectively. But it starts out accurately and then drifts away--> <div class="cmdBoxy" >&gt;<span class="copy" ></span> <div class="vintage blink"></div> </div> <input type="text" class="cmdBox" oninput="copy($('.cmdBox').val());" id="lp" onkeydown="enterCmd($('.cmdBox'))"> <style> .vintage{ position:relative; background-color:white; height:25%; width:2%; left:1.5%; font-size:1em; margin: 0px 10px; } .cmdBox{ position:relative; top:1rem; background-color:red; font-size:1em; height:1.5rem; width:99%; margin: 0; padding: 0px 8px; } .copy { font-size:1em; font-family: sans-serif; } </style>
about 4 years ago · Juan Pablo Isaza Denunciar
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