0

My javascript app uses both mousewheel (jquery plugin) event and left and right click events:

$(document).mousewheel(function(event, delta) {
    if (delta < 0) {
        swipeLeft(nextLink);
        return false;
    } else if (delta > 0) {
        swipeRight(prevLink);
        return false;
    }
});
$("#div")
    .on('contextmenu', function(ev) {
        if (ev.which == 3) {
            ev.preventDefault();   
            swipeRight(prevLink);
        }
    })
    .mousedown(function(ev){
        if(ev.which == 1) {
            swipeLeft(nextLink);
            return false; 
        }
    });
$('#div').click(function(ev){
    if (ev.which == 1) {
        swipeLeft(nextLink);
        return false;
    }
});

I want middle click have normal behaviour, i.e. not being interpreted as a mouse wheel event, but the delta value is always 1 when I middle-click.

Is there a way to isolate middle click from mouse wheel turn?

Does the order the mousewheel and click events are defined matter?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Paolo Benvenuto
  • 385
  • 4
  • 15
  • The mouse middle-click is button #3 ... `ev.which === 3` ... maybe you can check for that _before_ checking delta? (just a thought, completely untested) – Stephen P Oct 27 '17 at 20:53
  • There is also [auxclick](https://developer.mozilla.org/docs/Web/Events/auxclick) but it's not well supported -- see [this question](https://stackoverflow.com/q/41110264/17300) and the answers on it. – Stephen P Oct 27 '17 at 20:57
  • `which === 3` on my first comment may be wrong, I just took that from the question I cited. [MDN MouseEvent.button](https://developer.mozilla.org/docs/Web/API/MouseEvent/button) is a more authoritative source for the button values. – Stephen P Oct 27 '17 at 21:00
  • is it possible to define an unique event managing bot click and mousewheel? – Paolo Benvenuto Oct 28 '17 at 12:22
  • Custom events may help you — see ["Creating and triggering events"](https://developer.mozilla.org/docs/Web/Guide/Events/Creating_and_triggering_events) on [MDN](https://developer.mozilla.org/) and/or ["Introducing Custom Events"](https://learn.jquery.com/events/introduction-to-custom-events/) for jQuery events, and this [SO answer](https://stackoverflow.com/a/23344816/17300) for brief examples. – Stephen P Oct 30 '17 at 17:00

0 Answers0