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

170
Views
How to scroll by percentage in react?

I have a horizontally scrollable flexbox like this.

example

Each box width is 25%. I'm trying to scroll left and right using buttons. Now it scrolls by 420px as in the code, But this causes responsive issues. Is there any way to use "25%" instead of "420" in react.

const scrollLeftHandler = () => {
    var elmnt = document.getElementById("programCard");
    if (elmnt.scrollLeft !== 0) {
      elmnt.scrollLeft += -420;
      setIsRightSlide(true);
    } else {
      setIsLeftSlide(false);
    }
  };
  const scrollRightHandler = () => {
    var elmnt = document.getElementById("programCard");
    if (elmnt.scrollLeft % 420 === 0 && isRightSlide) {
      console.log("if");
      setIsLeftSlide(true);
      elmnt.scrollLeft += 420;
    } else if (isRightSlide) {
      elmnt.scrollLeft = elmnt.scrollLeft - (elmnt.scrollLeft % 420);
      elmnt.scrollLeft += 420;
      setIsRightSlide(false);
    } else {
      console.log("else", elmnt.scrollLeft);
      setIsRightSlide(false);
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use:

let step = (window.innerWidth || docElem.clientWidth || body.clientWidth)*(25/100)

You can replace 420 with step.

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!