'Centering top slider based on the scroll position

I have a web page that has two elements.

Top slider + list of items.

Top slider shows the categories. And it's a horizontal slider.

Beneath it, I have a list of items that are wrapped in containers and I link each category to each container. So that on the click of each category browser would scroll down to the relavent container.

I have done everything. But I want the selected item in the categories to be centered on the screen.

How can I do that? I'm stuck at this point.

Here's a codesandbox link : https://codesandbox.io/s/jovial-chaum-5yy4z2?file=/style.css



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source