Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!