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

98
Views
Scroll an overflow component in react/next

So I have a component that have a fixed width with an overflow-x-auto. I decided to hide the scroll bar and replace it with 2 arrow/button both left and right. If I click left, it scroll to left and vice versa. How can I achieve this functionality ?

this is my component

<div className={` vertical-card w-7/12 flex flex-row overflow-x-scroll no-scrollbar pb-4`}>
            {
                dataConselor.map((item, index) => {
                    return <VerticalCard key={item.id} name={item.nama} specialist={item.specialist} shortdesc={item.shortdesc} img={item.img} />
                })
            }

        </div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

  1. Target the scrollable element (you can use useRef, since it's react):
const scrollable = useRef(null);

<div id="myElement" ref={scrollable}>
...
</div>
  1. Create the scroll function:
const scrollIt = (toRight) => {
  const scrollLength = ... //Calculate your scroll length however you want.
  scrollable.current.scrollBy({left: scrollLength * (toRight ? 1 : -1), behavior: "smooth"});
}
  1. Add this function to the left/right buttons:
<div id="toLeft" onClick={()=>scrollIt(false)}>...</div>
<div id="toRight" onClick={()=>scrollIt(true)}>...</div>
about 4 years ago · Juan Pablo Isaza Report

0

As you are using tailwind css, you can use a tailwind carousal component to achieve this behaviour.

There are various carousals available over here.

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