Grsmto / simplebar

Custom scrollbars vanilla javascript library with native scroll, done simple, lightweight, easy to use and cross-browser.
http://grsmto.github.io/simplebar/
MIT License
6.02k stars 535 forks source link

SimpleBar + Scroll to Top #671

Open livegp opened 1 year ago

livegp commented 1 year ago

Hello! Thanks for the great library. How to combine SimpleBar and Scroll to Top

There is a Scroll to Top function that works only if SimpleBar is not connected. What settings are needed to fix this?

palyvodaBoi commented 3 months ago

Hey! I am also interested in this

Grsmto commented 3 months ago

Not sure what you meant by "if SimpleBar is not connected" but with the vanilla JS API it works like this:

const simpleBar = new SimpleBar(document.getElementById('myElement'));

simpleBar.getScrollElement().scrollTo(x, y)

for React

const scrollableNodeRef = React.useRef();

// then in a useCallback or useEffect
scrollableNodeRef.current.scrollTo(x, y);

<SimpleBar scrollableNodeProps={{ ref: scrollableNodeRef }}>
  // your content
</SimpleBar>;