Get if user react page end with vanilla javascript

There are multiple answers to this question on Stackoverflow, however the most of them does not work for me, or are written in jQuery. How do I check if page bottom has been reached with vanilla JavaScript, and add / remove classes, based on this value? Perhaps, I should add some additional offset?

const ERROR_OFFSET = 10;
const TOP_MIN_OFFSET = 100;

const doc = document.body;
const offset = window.innerHeight + window.pageYOffset;
const height = doc.scrollHeight;

if (offset >= height) {
  // We are on the bottom. Does not always work =(

113 thoughts on “Get if user react page end with vanilla javascript”

  1. I believe everything published was very logical.
    However, consider this, suppose you were to write a awesome
    title? I mean, I don’t wish to tell you how to run your website, but suppose you added
    a title to possibly get folk’s attention? I mean Get
    if user react page end with vanilla javascript –
    JavaScript Help is kinda boring. You could glance
    at Yahoo’s front page and note how they create post headlines to grab viewers to open the
    links. You might add a video or a related pic or two to get people
    interested about what you’ve got to say. In my opinion, it
    might bring your posts a little bit more interesting.