Is this the only place you used jQuery? If so, I would recommend using it for pure javascript. Everything you can do with jQuery, you can also use with React and pure JavaScript, and there is no overhead.
Here is your version of handleScroll . Note that the height of the document is known to be annoying when calculating, but I used the approach of this question (which just reproduces the jQuery implementation).
handleScroll() { var winHeight = window.innerHeight; // Annoying to compute doc height due to browser inconsistency var body = document.body; var html = document.documentElement; var docHeight = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); var value = document.body.scrollTop; ... }
Update
If you want to get the scroll position inside an element, you will need something like
var el = document.getElementById('story_body'); var minPixel = el.offsetTop; var maxPixel = minPixel + el.scrollHeight; var value = document.body.scrollTop;
source share