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

264
Views
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 answers
Answer question

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 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!