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

334
Vistas
behavior:smooth param breaks window.scroll in keyboard event in chrome

I am pulling my hair out because for some reason when I pass behavior: smooth as a parameter to window.scroll, the function stops working altogether in Chrome. Without behavior:smooth it scrolls as expected. I'm pretty sure this is a Chrome bug, but I've used behavior:smooth elsewhere without issue, so I'm wondering what's special about the config on this page which is causing the problem. Here's the set-up, which will hopefully allow you to reproduce:

I have a document with several viewport-sized divs like so:

html:

<body>
    <div class="slide" data-ind="0"></div>
    <div class="slide" data-ind="1"></div>
    <div class="slide" data-ind="2"></div>
</body>

css:

.slide{
  width:100%;
  height:100vh;
  border-bottom:1px solid black;
  box-sizing:border-box;
}

I'm trying to use an event listener to scroll to a slide when you press an arrow key, like so:

window.addEventListener('keydown',function(){
      if(event.key=='ArrowRight'){
        let el=document.querySelector('.slide[data-ind="1"]');
        let dist=el.offsetTop;
          window.scroll({
            top:dist,
            left:0,
            behavior:'smooth'
          })
      }
    })

Update: Some more testing has made it clear that the bug only happens when window.scroll is used within a keyboard event.

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

0

I was able to resolve this by adding event.preventDefault(); to the keyboard event. Still unclear if this is intended/standard behavior, as Firefox had no such issue even without adding this line.

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