Auto scroll div

How do I, with Vue, scroll a div to a specific place? I have a <li> list inside a <div> and I want Vue to automatically scroll down to the active element. I know the height of each element, so this is basically x position on top.

+4
source share
1 answer

div position to x position  

change the div value substantially top.

document.getElementById("myDiv").style.top = "100px";

Scroll the entire page to the X coordinate:

the first number is x to another y. So, if you know the position - just

window.scrollTo(x-coord, y-coord)

https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

+4
source

All Articles