Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
get the full height of the document, so that when you scroll all the way to the bottom the scrollY value matches the full length of the HTML document

I would like to use JS to calculate how far a user scrolled down a page.

I'm trying to use a combination of scrollY and document.body.offsetHeight

But what I'm finding is that scrollY at the bottom of a page is returning 6883 but the document.body.offsetHeight is returning a value of 7392 - which leaves me in a place where I can't calculate the how far a user scrolled down the document.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight

Typically, offsetHeight is a measurement in pixels of the element's CSS height, including any borders, padding, and horizontal scrollbars (if rendered). It does not include the height of pseudo-elements such as ::before or ::after. For the document body object, the measurement includes total linear content height instead of the element's CSS height. Floated elements extending below other linear content are ignored.

So if I understand this correctly, it's taking into account the document in view of the viewport - so that should return the value of 6883, the same if a user scrolls the full length of the page.

What property do you use to calculate full scrollable view of a document, to compare to the max value of scrollY?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please try using document.body.offsetHeight-window.innerHeight it should return the expected scrollable value.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda