Dek Dekku
Dek Dekku

Reputation: 1461

Catching events for mousewheel when Firefox is autoscrolling

I know there are many questions asking how to prevent the autoscrolling mode that Firefox activates when a page is bigger than the viewport and you press the middle mouse button.

But what I actually need is just being able to detect the mouseup event, when autoscrolling is active. The event just doesn't seem to propagate, so I don't know when (and more important where) the mouse button is released.

I could also settle for detecting when the autoscrolling mode is gone and the mouse usage is back to normal.

I've prepared a Plunk to play with. When it starts, middle click anywhere and the text in the box will update. If you press the button, more content is added to the page: middle click will activate autoscrolling and the mouseup event is lost forever.

Link

Upvotes: 0

Views: 240

Answers (3)

Dek Dekku
Dek Dekku

Reputation: 1461

Got it.

Even tho' Pieter's answer is not correct, it gave me the correct idea.

For some reason if you preventDefault() in the mousedown handler, the mouseup one starts working.

$(document)
  .on("mousedown", function(e) {
      if (e.which !== 2) return;
      $("#h").text("MouseDown");
      e.preventDefault();
    }).on("mouseup", function(e) {
      if (e.which !== 2) return;
      $("#h").text("MouseUp");
    });

Plunk with the solution

Upvotes: 0

HIRA THAKUR
HIRA THAKUR

Reputation: 17757

 $(document).ready(function(){

$("your id").on('mousedown', function(e) { 
   if( (e.which == 1) ) {
     alert("left button");
   } else if( (e.which == 3) ) {
     alert("right button");
   } else if( (e.which == 2) ) {
      alert("middle button"); 
   }
   e.preventDefault();
}).on('contextmenu', function(e){
   e.preventDefault();
});
});

http://jsfiddle.net/p49nF/

Hope,this helps.!!!

Upvotes: 1

Pieter
Pieter

Reputation: 1833

Does this give a result?

$(selector).live('mouseup', function(e) { 

    if(e.which == 1) {

        alert("left");

    }if(e.which == 3) {

        alert("right button");

    }else if(e.which == 2) {

        alert("middle button"); 

    }

    e.preventDefault();

});

Upvotes: 1

Related Questions