Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  194] [ 2]  / answers: 1 / hits: 199305  / 6 Years ago, mon, november 5, 2018, 12:00:00

I use reactjs and want to handle scroll with click event.



Firstly, I rendered list of posts with componentDidMount.



Secondly, by click event on each post in list, It will display post detail and scroll to top (because I put post detail to top position of page).



Thirdly, by clicking close button in post detail, it will return previous list of posts but I want website will scroll to exactly to position of clicked post.



I use like this:



Click event to view post detail:



inSingle = (post, e) => {
this.setState({
post: post,
theposition: //How to get it here?
});
window.scrollTo(0, 0);
}


I want to get state of theposition then I can do scroll exactly to position of clicked post by 'Close event'.


More From » reactjs

 Answers
7

This should work:



this.setState({
post: post,
theposition: window.pageYOffset
});

[#53173] Wednesday, October 31, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billosvaldor

Total Points: 601
Total Questions: 113
Total Answers: 113

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;