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

83
Visualizações
JS parallax effect / only usable for Images/Elements that are not positioned at the top

I'm currently trying to create a lightweight parallax effect in JS. The only problem that i'm running into is, when i try to assign the effect to elements mid-document. Here's the current code:

[].forEach.call(document.getElementsByClassName('parallax'), function (v) {
    window.addEventListener('scroll', function () {
        let eTop = $('parallax').offset();
        let value = window.scrollY;
        v.style.top = value * .5 + 'px';
    });
});

If i now assign the 'parallax' class to objects below the top position they get weirdly transformed because their respective position is calculated using window.scollY resulting in heavily transformed positions. I guess the best way to deal with it is to subtract the elements actual position on the document, right? And if so how to do it? (newbie here)

Thamks in advance!

about 4 years ago · Juan Pablo Isaza
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