0

I have a container with some elements (see image below), and whenever I click on one of the elements, I would like them for the user to be in the center of the container.

Container with my elements

My container where I would like to scroll to an element

I am using a ref array for all the elements, and whenever I click on an element I will call the scrollIntoView() function.

        itemsRef.current[curVideoPos]?.scrollIntoView({
            block: "center",
            inline: "nearest",
        });

The scroll function work how I want it to be, but the only problem is that the entire page gets also moved(scrolled). So what do I need to do so that the scrollIntoView() function only scrolles in on container and not the entire page?

1 Answer 1

1

You should do it like this:

element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' })
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I used this method but it still scroll the whole page...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.