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

77
Vistas
Prevent scrolling to focused input/textarea element on change

I made a quick sandbox here for demonstration.

const btn = document.querySelector("button")
const topTextarea = document.querySelector("#input1")

topTextarea.addEventListener("change", (e) => {
  e.preventDefault();
  e.stopPropagation()
})
topTextarea.addEventListener("keyup", (e) => {
  // e.preventDefault();
  e.stopPropagation()
})
topTextarea.addEventListener("keydown", (e) => {
  e.preventDefault();
  e.stopPropagation()
})
btn.addEventListener("click", () => {
  topTextarea.focus({
    preventScroll: true
  });
})
body {
  display: flex;
  justify-content: center;
  flex-direction: column;
}

textarea {
  height: 100px;
}

#demo {
  height: 3000px;
}
<textarea name="" id="input1" cols="30" rows="10">asdaasdasdsadasd</textarea>
<div id="demo"></div>
<button>Scroll Top element</button>
<textarea name="" id="" cols="30" rows="10">Bottom</textarea>

Issue: Focus on any of textarea on page. Scroll out of them(while they are focused) then type something. Default behavior happens, page scrolls to the focused element.

In the sandbox you can see a button which triggers focus but prevents scroll.

Is it possible to implement so that when on change happens, we prevent scroll ?

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

0

I found a solution.

Prevent keyDown event. Gather the entered char and update your 'state'.

And you can do some calculation and scroll to the element.

For my case scrollIntoView was causing issues with our design thats why i had to scroll manually.

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