fisshy / react-scroll

React scroll component
https://github.com/fisshy/react-scroll/blob/master/README.md
MIT License
4.36k stars 436 forks source link

A way to scroll an element into view #255

Open benogle opened 7 years ago

benogle commented 7 years ago

I have a short element on the page, and I want to minimally scroll the page to bring the element into view. scroller.scrollTo('element-name') scrolls the page to the top of the element, but I would like something more like https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

Is this possible today without calculation myself?

fisshy commented 7 years ago

Currently not, what you could do is set the offset based on 50% of the height of your element.

oldo commented 6 years ago

What about setting the offset to window.innerHeight / x?