Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda