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

120
Vistas
Display popup once users scrolls down to a section of page

I have a popup set to display once the user scrolls to a specific section on my page, however, if I reload the page, the page does not scroll all the way back to the top, immediately triggering the popup again on refresh.

Is there a conditional I can use to make sure this popup displays only when the user is starting from the top of the page? I don't like the way it automatically shows on a refresh if the scrollY is already passed the given section.

const section = document.querySelector('#section-1');
const card = document.querySelector('#card-popup');
const closebtn = document.querySelector('#close-popup');
let flag = false;


const cardPop = ()=>{
  const topOfSection = section.offsetTop;
  console.log(topOfSection);
  if (window.scrollY >= topOfSection && !flag) {
    card.style.display = "block";
    flag = true;
  }

  closebtn.addEventListener('click', (e) =>{
    card.style.display = "none";
  });
}

window.addEventListener('scroll', cardPop);
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