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.
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!
Most helpful comment
hi @jllagerberg .
scrollIntoViewis part of the web api, and you can find the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView