user6102188
user6102188

Reputation:

Automatically scroll div

How do I, with Vue, scroll down a div to a specific place? I have a list < li > inside a < div > and I want Vue automatically to scroll down to the active item. I know the height of each item, so it's basically x position from top.

Upvotes: 4

Views: 4463

Answers (1)

Lukas Liesis
Lukas Liesis

Reputation: 26393

position div to X location

basicly change such div's top value.

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

scroll entire page to X coordinate:

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

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

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

Upvotes: 4

Related Questions