capture in js when the middle mouse btn is clicked and that compas arrow appears...

Discussion in 'JavaScript' started by rajmv, Jun 15, 2012.

  1. #1
    Hi..

    For my opensourced scrollpane component, I'd like to be able to register when the middle mouse button is clicked and that 4-way compass arrow appears (on windows at least). From there it should be just a little hassle to track the mouse movements so that I can scroll my scrollpane in both left-right and top-down at the same time.

    But how do you register a click on that middle mouse btn in javascript?
     
    rajmv, Jun 15, 2012 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    stephan2307, Jun 20, 2012 IP
  3. rajmv

    rajmv Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the tip..
     
    rajmv, Jun 20, 2012 IP
  4. lampChamp

    lampChamp Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    With jQuery, this will tell you when the "middle click" is pressed, and cancel it. Change as you see fit.
    $(document).ready(function () {
        $(window).mousedown(function (e) {
            if (e.which == '2') {
                alert('Middle click pressed');
                
                e.preventDefault();
                return false;
            }
        });
    });
    Code (markup):
     
    lampChamp, Jun 24, 2012 IP