How to disable animation while animating using mousewheel and slick slider?

David Harroch

I have a slick slider on my website, and i'm using also jquery-mousewheel to switch slides. The issue is that i want to disable the mousewheel while it's sliding.

Do you know how i can do this ?

function detectScroll() {
  $('body').bind('mousewheel', function(e){
      if(e.originalEvent.wheelDelta /120 > 0) {
        $('.slickSlider').slick('slickPrev');
      }
      else{
        $('.slickSlider').slick('slickNext');
      }
  });
}

$('.slickSlider').slick({
  vertical: true,
  verticalSwiping: true,
  autoplay: false,
  slidesToShow: 1,
  slidesToScroll: 1,
  arrows: false,
  dots: false,
  infinite: false
})

detectScroll()

David Harroch

I found a solution!
The thing is that I had to declare a boolean that i called animating. Then I used the on('beforeChange') and on('afterChange') of slick to detect rather the animation is finished or not. And I just had to check if the the animating is true or false in the beginning of the mousewheel function and return false if it's true.

I hope it would help a lot of people!

var animating = false;

function detectScroll() {
  $('body').bind('mousewheel', function(e){
      //If animated than we wait the animation to be over
      if (animating) {
        return false;
      }
      if(e.originalEvent.wheelDelta /120 > 0) {
        $('.slickSlider').slick('slickPrev');
      }
      else{
        $('.slickSlider').slick('slickNext');
      }
  });
}

$('.slickSlider').slick({
  vertical: true,
  verticalSwiping: true,
  autoplay: false,
  slidesToShow: 1,
  slidesToScroll: 1,
  arrows: false,
  dots: false,
  infinite: false
})

$('.slick').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  animating = true;
}).on('afterChange', function(event, slick, currentSlide, nextSlide){
  animating = false
});

detectScroll()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to inherit animation properties while animating CALayer with implicit animation

Disable slider tracking animation?

How to display the fullscreen background image slider using the slick slider?

How to disable addEventListener with mousewheel event

CSS Animation with Fade Transition on Slick Slider

Disable sliding when selecting a slide in slick slider

How to replace timer pagination with progress bars using slick slider

How can I change the speed of slider using arrow in Slick Carousel?

How to change Slick Slider default arrow using data attributes?

Problems using Slick jQuery slider

Slick Slider using landscape and portrait

mousewheel event is too fast. How to disable it

Javascript - How to disable mousewheel for 1 second

SwiftUI how to implement animating image slider with indicator

how to make Slider Animation

How to disable page animation while loading in WP 8.1?

How to disable touch detection while Google Map animation is running in android

How to disable tabLayout scroll animation while scrolling it programetically?

How to programmatically disable constraint when animating

Disable centerMode if first or last slide is active - Slick Slider

Disable slick slider when viewport is less than 481px

disable previous arrow only one time in slick slider

Disable a transition while an animation is running

Disable Notepad++ Font Zoom using Ctrl+Mousewheel

Android translate animation instantly requires full height while animating

SVG is not showing center while animating and after finished animation

Temporarily disable/remove constraints while animating UI elements

Disable Buttons while animating a Uivew which is subview of main view

How to add slick-active class in Slider dots in React Slick