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

246
Visualizações
In a threeJS canvas with an animated scroll function, how do I prevent scrolling up beyond the top of the page?

I'm implementing a smooth scroll in Three.js based on this tutorial, it amounts to the following scroll listener:

window.addEventListener("wheel", onMouseWheel);

let y = 0;
let pos = 0;

function onMouseWheel(e) {
    y = e.deltaY * 0.003;
    particlesMesh.rotation.y += 0.0005;
}

And the following rendering:

const clock = new THREE.Clock();

const tick = () => {

// Scroll
    
    pos += y;
    y *= 0.9;
    camera.position.y = -pos;

// Render

    renderer.render(scene, camera);
    window.requestAnimationFrame(tick);
};

tick()

My question is: How can I prevent the user being able to scroll up/down infinitely. I'm a little unsure on how the webgl canvas effects the dimensions of the page, but it seems to go on forever.

I have tried to add a condition to only allow scrolling down if y > 0, but the scrollbar simply gets stuck at the top.

Is there a simple solution to prevent scrolling up when y <= 0?

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

0

e.deltaY is not the scroll position; it is merely the direction of the scroll. e.deltaY is positive when scrolling down and negative when scrolling up.

It sounds like you want to add constraints around the camera.position.y variable. If so, then add a condition before pos += y:

if(camera.position.y < 0) {
     ...
}
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