react-scroll icon indicating copy to clipboard operation
react-scroll copied to clipboard

React Scroll to component but have component be at bottom of page rather than top

Open arhoy opened this issue 4 years ago • 1 comments

Currently react Scroll to a specific elements is working wonderfully, but it is scrolling to a an element so that the element is at the top of users' page. I would like to be able to scroll so the element is at the bottom of the page rather than at the top. Even better is if the target element could scroll to the users' click position, ie where you set the Scroll.Link element. Is this possible.

An example use case would be, I have a bunch of reviews, each with an edit button if that user made the review. I also have a form at the top of the page to create a review. I would like to be able to have the form appear where the user clicked.

Thanks!

arhoy avatar Nov 24 '19 01:11 arhoy

It could be possible if you were to calculate the position of the scroll. You could take the current scroll position and take the position of the current click.

const scrollToY = clickedPosition - currentScrollPosition ;
scroller.scrollTo(scrollToY);

fisshy avatar Nov 25 '19 06:11 fisshy