Linus Stolz
Linus Stolz

Reputation: 11

Disabling Mouse Wheel for X Milliseconds with javascript?

I have a Website with RoyalSlider and Mousewheel support. http://www.linus.de/mark/drei.php

Everything works fine, but when i use my macbook (touchpad) the thing is that i fire several mousewheel events at a time when scrolling. so basically i want the script to pause for the time (or a bit less) it takes for one slide to change...

What i would need is a javascript which freezes the mousewheel for x milliseconds each time it's been triggered (after sending 1 or -1 to the slider)...

Upvotes: 0

Views: 195

Answers (2)

matewka
matewka

Reputation: 10148

I can't give you a full code example since you didn't give any code to us but here's the solution.
When you scroll the mouse, a scroll animation begins. Create a variable somewhere outside the event handler, let's say

var animationInProgress = false;

and set it to true right before the animation begining. Then, this RoyalSlider plugin must have some kind of complete handler (I bet it has - it's paid though) - a parameter where you can put a function to be called when the animation is over. So, you put there a function similar to that:

function() {
    animationInProgress = false;
}

The last thing is to check the value of the animationInProgress variable each time you want to run an animation

if (false === animationInProgress) {
    //run the animation
}

I hope you get the idea.

Upvotes: 0

Ryan Erb
Ryan Erb

Reputation: 838

A Timer with a call back and a flag could work. When you start to scroll you set the flag and not allow the scroll wheel to function, see This Answer on how to disable the scroll wheel. When the timer fires (1 second or so) you reset the flag to let the person scroll again. See This page for how to set up a timer with a call back

Upvotes: 2

Related Questions