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

135
Views
La función Jquery funciona solo en el primer elemento, quiero trabajar en todas las clases

He creado una función Jquery que se ve así

 jQuery(document).ready(function ($) { var animations = document.querySelectorAll('.slide-up'); for (var i = 0; i < animations.length; i++) { var windowHeight = window.innerHeight; var elementTop = animations[i].getBoundingClientRect().top; var elementVisible = 140; if (elementTop < windowHeight - elementVisible) { animations[i].classList.add("active"); } else { animations[i].classList.remove("active"); } }});

El problema es que funciona solo en la primera clase cuando me desplazo hacia abajo, quiero trabajar en cada clase. También intento algo como:

 jQuery(document).ready( function($){ $('slide-up').each(function($) { var animations = document.querySelectorAll('.slide-up'); for (var i = 0; i < animations.length; i++) { var windowHeight = window.innerHeight; var elementTop = animations[i].getBoundingClientRect().top; var elementVisible = 140; if (elementTop < windowHeight - elementVisible) { animations[i].classList.add("active"); } else { animations[i].classList.remove("active"); } } });});

Pero con los mismos resultados. ¿Alguna idea o sugerencia sobre cómo aplicar a todos los elementos que tienen la clase .slide-up cuando me desplazo hacia abajo?

Gracias por adelantado !

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

0

Considera lo siguiente.

 jQuery(function($) { var animations = $('.slide-up'); var windowHeight = window.innerHeight; var elementVisible = 140; animations.each(function(i, el) { var elementTop = $(el).position().top; if (elementTop < windowHeight - elementVisible) { $(el).toggleClass("active"); } }); });

Esto debería realizar una acción en cada elemento. Todo el código se ha cambiado a jQuery.

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!