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

275
Visualizações
How can I change the scene background color on scroll in Three JS?

I am trying to make a website where you have a background color at the start, and when I scroll to a certain part it eases into another color. I can do it to the point that it changes on scroll, but it changes right away and isn't locked to the scroll position, so it stays that way.

This is my original color:

scene.background = new THREE.Color(0x007ca9);

I want it to change when it reaches div page-2.

<body>
  <canvas id="bg"></canvas>
  <main>
    <div class="page-1" data-color="blue">
      <ul>
        <img class="logo" src="logo.png">
        <h1>whatever</h1>
      </ul>
    </div>
    <div class="page-2" data-color="grey">
      <h1>whatever</h1>
    </div>

  </main>

</body>

And here is the onscroll function I'm currently using, which doesn't get the job done obviously.

function changeColor() {
  scene.background = new THREE.Color(0x24252a)
}

document.body.onscroll = changeColor;

I'm somewhat of a beginner so any help that is as simple as possible would be much appreciated.

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