I am currently working on a Vue page that consists of two divs. The Select-Div contains a list of elements, and when I click on an element from the list, the Scroll-Div is supposed to scroll to the corresponding ID element inside it. Ideally, the scrolling should position the element in the center of the Scroll-Div, where detailed information about the selected list element is displayed.
The issue I'm facing is that when I use scrollIntoView, the entire page scrolls to the center as well. This causes both the Scroll-Div and the main page to move, which is not the desired behavior.
It's important to note that the Scroll-Div includes a recursive component, so I am restricted to using IDs instead of refs.
Here is my goTo() function defined on the main page:
goTo(id) {
const element = document.getElementById(`Id-${id}`);
if (element) {
element.scrollIntoView({
block: "center",
behavior: "smooth",
});
}
},
This function receives the emitted ID from the Select-Div and scrolls to the corresponding HTML ID within the Scroll-Div.