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

184
Views
Intersection Observer: cómo usar addClassList en todos los elementos de la misma clase

Estoy tratando de activar las animaciones CSS de mi página solo en la ventana gráfica del usuario. Lo que significa que la animación comenzará solo una vez que el elemento sea visible. Para eso decidí usar Intersection Observer pero solo agrega mi clase al primer elemento con ese nombre de clase, en lugar de todos ellos.

JS: .animate__animated tiene la propiedad 'animation-play-state: paused' de forma predeterminada, y si la clase está visible, agrega la clase 'is-running' que contiene 'animation-play-state:running'. Funciona muy bien con el primer elemento, pero no con el segundo (y otros en mi página).

¿Cómo puedo pasar todas las instancias de esa clase a las entradas? ¿Puedo incluso hacer eso con el Intersection Observer? Soy nuevo en JS, principalmente sigo tutoriales en línea y parece que no puedo encontrar una solución.

 const observer = new IntersectionObserver(entries => { // Loop over the entries entries.forEach(entry => { // If the element is visible if (entry.isIntersecting) { // Set to animation-play-state: running entry.target.classList.add('is-running'); } }); }); observer.observe(document.querySelector('.animate__animated'));

CSS:

 .animate__animated { -webkit-animation-duration: 1s; animation-duration: 1s; -webkit-animation-duration: var(--animate-duration); animation-duration: var(--animate-duration); -webkit-animation-fill-mode: both; animation-fill-mode: both; animation-play-state: paused; } .is-running { animation-play-state: running; }

HTML:

 <nav class="navbar has-text-white has-shadow" style="background:#231f20; max-height:80px;"> <div class="navbar-brand"> <a href="index.html" class="narvbar-item pl-2"> <img src="img/logo-txt.png" alt="Cheff Burgers Logo" class="pt-4 pl-5 animate__animated animate__lightSpeedInLeft" > </a> <a class="navbar-burger has-text-white" id="burger"> <span></span> <span></span> <span></span> </a> </div> <div class="navbar-menu pb-5" id="nav-links" style="background-color:#231f20;"> <div class="navbar-end pr-6 mr-6 mt-5 animate__animated anim1 animate__lightSpeedInRight"> <a href="index.html" class="navbar-item has-text-white">Accueil</a> <a href="menu.html" class="navbar-item has-text-white">Menu</a> <a href="evenements.html" class="navbar-item has-text-white">Evènements</a> <a href="contact.html" class="navbar-item has-text-white">Horaires & Contact</a> </div> </div> </nav>
about 4 years ago · Juan Pablo Isaza
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!