react-scroll Scroll link disabled on scrolling down a little

47 views Asked by At

I was trying to implement a scroll bar for a definitionslist page i am working on the scrolling to works fine when if i dont scroll down a little i have sort of figured out the problem i think its a problem of giving the top in the css styling but i need that can anyone help me work aorund this thank you.

here is the code i have

   <div className="fixed w-full pt-20 bg-white p-4 ">
        {" "}
        <nav className=" borde borde-red-900 bg-white ">
          <ul className="flex space-x-4">
            {alphabet.map((letter) => (
              <li key={letter} className="sticky top-14  z-50">
                <ScrollLink
                  to={letter}
                  activeClass="active"
                  smooth={true}
                  offset={-150}
                  duration={500}
                  className="text-blue-500 border border-red-900 pt-[-20px] hover:underline hover:cursor-pointer sticky top-14  z-50"
                  onClick={() => scrollToSection(letter)}>
                  {letter}
                </ScrollLink>
              </li>
            ))}
            <li>
              <ScrollLink
                to="numeric"
                smooth={true}
                duration={800}
                className="text-blue-500 hover:underline cursor-pointer"
                onClick={() => scrollToSection("numeric")}>
                #
              </ScrollLink>
            </li>
          </ul>
        </nav>
      </div>

I tried removing the top and adding a padding or margin but those didnt work either. the scroll started working perfectly when i removed it out of the fixed/sticky div but i want the scroll bar to be fixed or sticky i think it likely means that the fixed header was covering the content, making the links unclickable. any help would be great or a better way to implement what i tried thank you

1

There are 1 answers

1
Mohd Ruman On

If the scroll link gets disabled or stops working when scrolling down a little, it might be due to the offset value you've set in the react-scroll ScrollLink component. The offset determines the vertical offset of the target scroll position, and if it's not properly configured, it can cause the scroll behavior to be incorrect.

try tweeking it a bit and see if it fixes the problem.

<div className="pt-20 bg-white p-4">
  <nav className="borde borde-red-900 bg-white">
    <ul className="flex space-x-4">
      {alphabet.map((letter) => (
        <li key={letter}>
          <ScrollLink
            to={letter}
            activeClass="active"
            smooth={true}
            offset={-100} // Adjust the offset value as needed
            duration={500}
            className="text-blue-500 border border-red-900 pt-[-20px] hover:underline hover:cursor-pointer"
            onClick={() => scrollToSection(letter)}>
            {letter}
          </ScrollLink>
        </li>
      ))}
      <li>
        <ScrollLink
          to="numeric"
          smooth={true}
          duration={800}
          offset={-100} // Adjust the offset value as needed
          className="text-blue-500 hover:underline cursor-pointer"
          onClick={() => scrollToSection("numeric")}>
          #
        </ScrollLink>
      </li>
    </ul>
  </nav>
</div>