Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
Hide the block at the end of the page

I have a block that appears after scrolling 1000px on the page

const navShareLink = document.getElementById('navShareLink');
document.addEventListener('scroll', function(e) {
  if(window.scrollY > 1000 && window.innerWidth > 576) {
    navShareLink.style.display = "block";
  } else {
    navShareLink.style.display = "none";
  }
});

But when it reaches the end of the page where the footer is, I need it to hide back so that it does not climb into the footer

It's easy to do if the page has the same height, but for me it can be either 2500px or 5000px

Is it possible to somehow count the pixels in reverse order, but not from the beginning of the page, but let's say 300px from the end?

In my example, I try to get the height of the page and subtract 300px from it to set the desired value

const navShareLink = document.getElementById('navShareLink');
let pageHeight = document.documentElement.scrollHeight;
let endPageHeight = alert(pageHeight - 300);

document.addEventListener('scroll', function(e) {
  if(window.scrollY > 1000 && window.innerWidth > 576) {
    navShareLink.style.display = "block";
  } 
  else if(window.scrollY > endPageHeight && window.innerWidth > 576) {
      navShareLink.style.display = "none";
  }
  else {
    navShareLink.style.display = "none";
  }
});

But this line document.documentElement.scrollHeight; does not accept a numeric value, but displays this number on the page in a popup tab, and actually nothing works further

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda