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

146
Views
how to change carousel slide on mousewheel

I'm working on a project and I need to create a vertical carousel that works on scroll (mousewheel) I just need to know how can I handle the sliding on scroll.

I have a function called nextSlide when I call then it get the next slide.

I did something like this (I checked the direction and other stuff but I'm adding the simplest code snippet here)

Note: I did Debounce on my function but it didn't work

el.addEventListener('wheel', (event) => {
  event.preventDefault();
  nextSlide();
});

The problem here is the event firing on each mouse scroll I just need to handle it on one scroll here is an example from swiper

https://codepen.io/Seamni69/pen/vYgmqVd

What I meant by one scroll is calling the function just one time when scrolling, no matter how much scrolling is.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Created this. if wheelDeltaY is positive, you are scrolling down. If it's negative you are scrolling up.

window.addEventListener('wheel', throttle(scrollDirection, 500));

function scrollDirection(e) {
  e.preventDefault();

  e.wheelDeltaY > 0 
    ? console.log("DOWN") 
    : console.log("UP")
  e.stopImmediatePropagation();
};

function throttle(func, interval) {
  let lastCall = 0;
  return function() {
    const now = Date.now();
    if (lastCall + interval < now) {
      lastCall = now;
      return func.apply(this, arguments);
    }
  };
}

about 4 years ago · Juan Pablo Isaza Report
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!