Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Jquery function is working just on first element, I want to work on all classes

I've created a Jquery function that looks like this

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");
    }
}});

The problem is, it is working just on the first class when I'm scrolling down, I want to work on each class.I also try something like:

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");
        }
    }
});});

But with same results.Any ideas or suggestion about how to apply to all elements that have .slide-up class when I'm scrolling down ?

Thanks in advance !

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Consider the following.

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");
    }
  });
});

This should perform an action on each element. All code has been switched to jQuery.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda