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

308
Visualizações
How to paralax?

i'm trying to learn how to use the paralax effect using simple javascript and css. my javascript is :

window.addEventListener('scroll', function(){
        document.getElementById("second").style.left = window.scrollY + 'px';
        document.getElementById("third").style.left = window.scrollY + 'px';
    })

from my understanding of things, it should make the element called third and second scroll left by the same value as the vertical scroll. But it doesn't work and I can't find what's the problem here.

My whole code is:

<!DOCTYPE html>
<html>
<head>
    <title>paralax</title>
    <style>
        *{
            scroll-behavior: smooth;
        }
        section{
            position: relative;
            width: 100%;
            height: 100vh;
            padding: 100px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        section::before{
            content: '';
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 100px;
            background-image: linear-gradient(to bottom right, #350529 , #45392c);
            z-index: 100;
        }
        section img{
            position: absolute;
            top:0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        section img#sixth{
            z-index: 10;
        }
        #text{
            position: absolute;
            color: white;
            white-space: nowrap;
            font-size: 7.5vw;
            z-index: 9;
        }

    </style>
</head>
<body style="size: 100%; margin-top: 0px; margin-left: 0px;">
    <section>
        <img src="Plan-parallax-1.png" id="first">
        <img src="Plan-parallax-2.png" id="second">
        <img src="Plan-parallax-3.png" id="third">
        <img src="Plan-parallax-4.png" id="fourth">
        <img src="Plan-parallax-5.png" id="fifth">
        <h2 id="text">Monde parallele</h2>
        <img src="Plan-parallax-6.png" id="sixth">
    </section>
    <script>
        window.addEventListener('scroll', function(){
            document.getElementById("second").style.left = window.scrollY + 'px';
            document.getElementById("third").style.left = window.scrollY + 'px';
        })
    </script>
</body>
</html>
```
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