4

how can I trigger two mouse events simultanious (hold right clic and mouse weel) I have to press the right button of the mouse and hold on and at the same time I roll the wheel

    $("selector").bind("click mousewheel", (function(event, delta) {
           console.log("xxx")});
Arbia CHARFI
  • 131
  • 1
  • 8

2 Answers2

2

This may be not exactly you want but it works...

Fiddle here

var rightButtonDown = false;
$(document).mousedown(function (e) {
    if (e.which === 3) rightButtonDown = true;
});
$(document).mouseup(function (e) {
    if (e.which === 3) rightButtonDown = false;
});
$(document).mousewheel(function (event, delta, deltaX, deltaY) {
    if (rightButtonDown) {
        console.log("fire!")
    }
});

Include a jQuery plugin to handle the mousewheel event.

lastr2d2
  • 3,604
  • 2
  • 22
  • 37
1

Try this demo http://jsfiddle.net/HeDPZ/

Try event mousedown for any kind of click i.e. right or left.

Behavior - with the mouse click of when you move wheel you will see an alert poping.

Another thing is there is a small syntax error in your closing brackets.

For OP: Do you mind telling us bit more as to what kind of functioanlity you are aiming for just so that we can help you out in more detail.

Captureing event like this http://jsfiddle.net/dQWNY/ more here: Detect middle button click (scroll button) with jQuery

  • Left - 1
  • Middle - 2
  • Right - 3

I hope this is fits your need :)

Code

$(".vendor-icon").bind("mousedown mousewheel", function (event, delta) {
    alert("xxx");
});

Associated html

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • I think the OP is looking to detect when only both events are true "simultanious", not when either is true. – j08691 Oct 18 '13 at 01:53
  • @j08691 Hiya bruv, I reckon this will work when both happens at same time `:)` coz of `mousedown` event. will treat any button down in mouse interface as mouse down. – Tats_innit Oct 18 '13 at 01:55
  • @RUJordan Hiya man, I tried and it seemed to be working, Try pressing the missing Wheel of mouse with scrolling action and you will see the click `:))` although thius is very weird requirement :P – Tats_innit Oct 18 '13 at 01:56
  • My apologies, my trackpad doesn't seem to function like a mouse (obvious reasons). Question: is there a way to make this trigger ONLY when both events happen? – Sterling Archer Oct 18 '13 at 01:58
  • @RUJordan No worries bro! Sure `:)` yes I reckon something like this `e.which` so capturing the target event and which key. **I guess** something like this: http://stackoverflow.com/questions/5392442/detect-middle-button-click-scroll-button-with-jquery is conditional check `&&` should suffice, OP read this comment. – Tats_innit Oct 18 '13 at 02:00
  • 1
    Would you mind showing a mini-example/a fiddle? (Or is it simply 2 if statements inside the trigger?). Either way, +1. – Sterling Archer Oct 18 '13 at 02:01
  • @RUJordan Saweet bruv, cheers for that! I will try and script small demo soon-ish `:)` – Tats_innit Oct 18 '13 at 02:02