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

152
Visualizações
How to correct handle scroll position?

I've had a problem with scrolling div with using flex-direction: column-reverse;

Here is my 'visible' part of code:

.messagesBox {
  overflow-y: scroll;
  padding: 10px;
  row-gap: 2px !important;
  overflow: auto;
  display: flex;
  flex-direction: column-reverse;
  width: "100%";
}

<div
   id="messagesBox"
   onScroll={onScroll}
   className={styles.messagesBox}
>
   {renderContent()}
</div>

I create this div to display an array of object, set vertically with scrool sticky to bottom thanks to column-reverse (i need to use this because i have no contact with server side).

Here is my onScroll function:

  const onScroll = () => {
    const box = document.getElementById("messagesBox");
    console.log(box.scrollTop);//-267 on top div, 0 on bottom div, I need reverse this values
  }

when I scroll my div to top the scrollTop function return me bad values, when I'm on top she return me some negative values like -267.7, but when i scroll to bottom then return me 0.

Can someone tell me how to get correct values and get 0 from scrollTop when scrool is on top?

Thanks for any help!

////////////////////////////

about 4 years ago · Juan Pablo Isaza
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