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

176
Vistas
Show Button only particular area while scrolling

Need to show Button between 370px to 410px while scrolling in the Page.


useEffect(() => {
    document.addEventListener('scroll', () => {
      try {
        if ((document.body.scrollTop < 410 || document.documentElement.scrollTop < 410) && (document.body.scrollTop > 370 || document.documentElement.scrollTop > 370)) {
          setBtn(true);
        } else {
          setBtn(false);
        }
      } catch (e) {
        console.error(e);
      }
    });
  }, [Btn]);

{Btn ? <button>Submit</button> : null}

Suggest me, how to solve this because this above code is not working.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem with your validation is that using an || operator using two ways of getting the scrollTop is causing your issues, because in chrome document.body.scrollTop returns 0, and that guarantees that the first part of your condition will always be true. So you need to separate for each way of getting the scrollTop

In other words, your if should have this instead:

((document.body.scrollTop < 410 && document.body.scrollTop > 370) || (document.documentElement.scrollTop < 410 && document.documentElement.scrollTop > 370))

Also here's a better explanation of the scrollTop problem

about 4 years ago · Juan Pablo Isaza Denunciar
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