Simplebar: Scroll to elements inside of the simplebar

Created on 14 Jan 2020  路  3Comments  路  Source: Grsmto/simplebar

Is it possible to scroll to elements inside of the simplebar?

I was able to get a scroll to top function working by doing this:

const container = document.querySelector('#my-container .simplebar-content-wrapper');
container.scrollTo({ top: 0, behavior: 'smooth' });

But I also need to be able to scroll to specific elements inside of it. How can I achieve this?

I am using SimpleBar with the data-simplebar attribute.

question

Most helpful comment

hi @jllagerberg .
scrollIntoView is part of the web api, and you can find the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

All 3 comments

I found the solution:

document.querySelector('#element-name').scrollIntoView({ behavior: 'smooth' });

Why is this not documented somewhere?

hi @jllagerberg .
scrollIntoView is part of the web api, and you can find the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

That's correct, this is documented on MDN because it's not related to this library since it's a native API!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrey-evstigneev picture andrey-evstigneev  路  3Comments

Blackleones picture Blackleones  路  3Comments

TheeOhioState picture TheeOhioState  路  6Comments

EmilMoe picture EmilMoe  路  4Comments

RennerBink picture RennerBink  路  3Comments