Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a MouseUp event outside the window?

I am looking for jQuery solution to detect mouseup outside the window. That is, after the mouse has been downed inside the window, dragged outside while still down, and then released outside, is when the event should fire.

I tried document.mouseup = function() {}, it didn't help. I tried to follow the example here, but couldn't properly understand it (I even left a comment asking for help, but no help yet..:( )

like image 514
SexyBeast Avatar asked Feb 16 '13 16:02

SexyBeast


People also ask

Does mouseup fire before click?

Mouseup is always firing before click, despite this order.

How do I trigger a mouseup event?

The mouseup event occurs when the left mouse button is released over the selected element. The mouseup() method triggers the mouseup event, or attaches a function to run when a mouseup event occurs. Tip: This method is often used together with the mousedown() method.

When a user mouse over something it triggers the event?

The mouseover event occurs when a mouse pointer comes over an element, and mouseout – when it leaves. These events are special, because they have property relatedTarget . This property complements target . When a mouse leaves one element for another, one of them becomes target , and the other one – relatedTarget .

What is a mouseup event?

The mouseup event is fired at an Element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is located inside it. mouseup events are the counterpoint to mousedown events.


1 Answers

I have a website that uses this event and it works as you described:

$(window).on('mouseup', function(){
   //your code here
});

Note: only tested in jQuery 1.8.3, but it should work in 1.9

jsFiddle confirms. Works in jQuery 1.9.1 and 2 beta: http://jsfiddle.net/udRNx/1/

In case you didn't know, this piece of code must be placed in either $(document).ready(fn) or $(window).onload(fn).

like image 200
GeriBoss Avatar answered Sep 25 '22 05:09

GeriBoss