Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Ejecutar detector de eventos solo una vez con desplazamiento

Tengo un detector de eventos para una imagen que se desvanece al desplazarse hacia abajo y quiero que deje de reaparecer al desplazarse hacia arriba.

Aquí está mi código, ¿podrían ayudarme con eso?

 const checkpoint = 100; window.addEventListener("scroll", () => { const currentScroll = window.pageYOffset; if (currentScroll <= checkpoint) { opacity = 1 - currentScroll / checkpoint; } else { opacity = 0; } document.querySelector(".front").style.opacity = opacity; });

Gracias por adelantado

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Según su propia condición de currentScroll <= checkpoint , esto debería evitar que cambie la opacidad (es decir, evitar que la imagen vuelva a aparecer) una vez que se haya establecido en 0

 let checkpoint = 100; window.addEventListener("scroll", () => { const currentScroll = window.pageYOffset; if (currentScroll <= checkpoint) { opacity = 1 - currentScroll / checkpoint; } else { opacity = 0; checkpoint = -1; } document.querySelector(".front").style.opacity = opacity; });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!