Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
How can I scrollIntoView/focus without the smooth scrolling animation? like focusing instantly on an element

I've tried setting behavior: 'instant' in the scrollIntoView options, but it didn't work, and also preventScroll: false for focus options, but it still scrolls smoothly to reach the element

on this page https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus in the last code snippet, it behaves like what I want, it instantly focuses on the element, without the scrolling animation, but for me, it always scrolls smoothly until it reaches the element, how can I disable that scrolling animation?

// Show next page
function showNextPage() {
    let currPage = parseInt(pageCounter.textContent);
    let target = document.querySelector(`[data-page="${currPage + 1}"]`);
    target.focus({ preventScroll: false }); // DIDN"T WORK
}

// Show next page
function showNextPage() {
    let currPage = parseInt(pageCounter.textContent);
    let target = document.querySelector(`[data-page="${currPage + 1}"]`);
    target.scrollIntoView({ behavior: 'instant' }); // DIDN"T WORK
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

scrollIntoView with no parameter should scroll instantly.

function showNextPage() {
    let currPage = parseInt(pageCounter.textContent);
    let target = document.querySelector(`[data-page="${currPage + 1}"]`);
    target.scrollIntoView();
}

Also, you should remove scroll-behavior: smooth if you have any in your element's CSS. That could also cause smooth scrolling.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda