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

277
Visualizações
How to use a mousewheel as a prev and next by depending on wheelDeltaY

So I'm having a issue wherein mousewheel should be a next and prev button...I'm using a ThreeJS and I'm since this logic can be also implemented in some area I just wanted to phrase it in ThreeJS. So my problem here is that think about an array whose array = [image1,image2,image3] giving that

        let next = 0;
        let prev = 0;

        window.addEventListener("mousewheel",(e) => {
            move += e.wheelDeltaY/1000;

            next = Math.floor(move + 40) % 2;
            prev = ( Math.floor(move) + 1 + 40) % 2;

            console.log(array[next])
            console.log(array[prev])
        })

As you see next and prev is a modulo so that it only gives a 1 and 0 value.. Now the thing is that..since I have 3 arrays I want them to get input in the and next and prev.. let say I have 10 items images for array then next and prev will be something like this [img1,img2] first next and prev and then [img2,img3]...and so on... but until it reach [img9,img10]..it must still keep going as a loop( Just like sliders loop)

My code in ThreeJS is something like this

        let textures = [
            new THREE.TextureLoader().load(mask2),
            new THREE.TextureLoader().load(mask3),
            new THREE.TextureLoader().load(mask4),
            new THREE.TextureLoader().load(mask5),
            new THREE.TextureLoader().load(mask6),
        ]

        let next = 0;
        let prev = 0;

        window.addEventListener("mousewheel",(e) => {
            move += e.wheelDeltaY/1000;

            next = Math.floor(move + 1000) % 2;
            prev = ( Math.floor(move) + 1 + 1000) % 2;
            console.log(next,prev)

            material.uniforms.t1.value = textures[prev];
            material.uniforms.t2.value = textures[next];

        })

UPDATE:

            next = Math.floor(move + 1000) % textures.length;
            prev = ( Math.floor(move) + textures.length + 1000) % textures.length;

I have an answer now but I want something better than this..because I want to specifically make their length of moves..If cannot be answer thats fine thanks. for example the length of scrolling must be 40 or something else so that it will not switch just quickly.

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