Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!