Is it possible to trigger mouse events when the cursor is outside the page?

I am creating a game in which you can hold down the mouse button and drag it around to rotate an object. However, when the mouse position is outside the borders of the page, all mouse events are no longer triggered. This means that the object no longer rotates when the cursor is outside the page; in addition, when the user releases the mouse outside the borders of the page, I can’t keep track of what it means that the object is still rotating when the cursor returns to the borders of the page, although it is no longer pressed.

So, is there a way to make the mousemove / mousedown / mouse [...] events fire when the cursor is outside the borders of the page?

+2
source share
4

. mouseout mouseup.

+3

, , !

+1

ya, that doesn't make sense that you can still. If you do not interact with the browser, then how does the browser know what to do?

+1
source

You can use mouseleave, which works in jQuery 1.4.

In jQuery:

$("body").mouseleave(function() {
    //Your code here
    alert("Mouse has left");
});

This works in Firefox and IE7 from my testing.

http://www.bennadel.com/blog/1805-jQuery-Events-MouseOver-MouseOut-vs-MouseEnter-MouseLeave.htm

+1
source

Source: https://habr.com/ru/post/1789244/


All Articles