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

267
Vistas
How to execute css classNames code in a certain height using JavaScript?

I am trying to execute some CSS code at a certain height on scroll.

I would appreciate your help:)

here is a bit of code.

    @keyframes fadeInTop{
  0% {
      opacity: 0;
      transform: translateY(-50px);
  }
  100% {
      opacity: 1;
      transform: translateY(0);
  }
}

thanks!

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

0

Here is the solution

1.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Simple scroll example</title>
    <style>
      body {
        overflow: hidden;
      }
      section {
        height: 100vh;
        width: 100%;
        overflow: auto;
        background-color: #f0db4f;
      }
      section p {
        height: 300vh;
      }
    </style>
  </head>
  <body>
    <section
      id="section_scroll"
      class="scroll-section"
    >
      <p>Mouse Scroll Down</p>
    </section>
    <script>
      const link = document.createElement("link");
      link.rel = "stylesheet";
      link.type = "text/css";
      link.href = "1.css";

      const cssRunPosition = 100;
      const scrollSection = document.getElementById("section_scroll");

      scrollSection.addEventListener("scroll", event => {
        const y = scrollSection.scrollTop;
        if(y > cssRunPosition) {
          scrollSection.appendChild(link);
        }
      }, { passive: true });
    </script>
  </body>
</html>

1.css

.scroll-section {
  animation-name: fadeInTop;
  animation-duration: 0.5s;
}

@keyframes fadeInTop{
  0% {
    opacity: 0;
    transform: translateY(-50px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
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