Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable multiple-scroll effect in osx and fire scroll event once per scroll

I need to organise navigation like jquery.fullPage: when I scroll once - I move to next section.

I tried to use jquery.mousewheel for it, but it fails in MacOS with touchpad or trackpad or APPLE Magic Mouse: It scrolls multiple slides per one scroll.

I tried to use this solution: https://github.com/jquery/jquery-mousewheel/issues/36#issuecomment-67648897

It works fine in Chrome, but it does not in FF and has bugs in Safari.

This is simple demonstration of issue: http://jsfiddle.net/ss5LueLx/13/

$slider.on('mousewheel', function(event) {
    if (event.deltaY>0) {
        slider.prevSlide();
    } else {
        slider.nextSlide();
    }
});
like image 373
Max Vorozhcov Avatar asked Apr 14 '15 13:04

Max Vorozhcov


1 Answers

I tested this statement in my SeaMonkey browser and it fails.

var delta  = e.type == 'mousewheel' ? e.originalEvent.wheelDelta * -1 : 40 * e.originalEvent.detail;

Just in case, I looked at the deltaY and it works: +1 in one direction and -1 in the other, just as you determined in the other two implementations you have.

console.log(e.deltaY); // view console in FireBug

Looking at the event structure in Firebug, I can see that the event type is "mousewheel", and yet I do not see a wheelData field in the originalEvent.

And although there is a detail field, but that one remains at zero.

I would imagine that you are attempting to go to the next item only once you reach +/-3. I would suggest something of the sort to accomplish this feat:

// somewhere, initialize to zero
var current_position = 0;


// on mousewheel events
current_position += e.deltaY;

// you had a x 40 which would indicate that the limit is about 120 / 40
// if 3 is too small, you can always increase it to 5 or event 10...
if(current_position <= -3)
{
  slider.nextSlide();
  current_position = 0;
}
else if(current_position >= 3)
{
  slider.prevSlide();
  current_position = 0;
}

Otherwise you could verify that your allowScroll flag works as expected. I do not program objects that way so I am not too sure whether it is correct or not. (I use the prototype syntax which is useful if you want to extend classes.)

like image 197
Alexis Wilke Avatar answered Oct 17 '22 17:10

Alexis Wilke