5

No jQuery possible.

How to disable / stop mouse movement with JavaScript?

What to do: If the mouse is being moved to, let's say, position left < 300, disable ouse movement to prevent further moving into this direction.

Is that possible?

Shlomo
  • 3,880
  • 8
  • 50
  • 82
  • Of course not, why would you want to do this? – Esailija Nov 16 '12 at 11:08
  • 2
    I love javascript, but I really hope it will not ever be able to control my mouse. – Amberlamps Nov 16 '12 at 11:08
  • You can hide cursor after `left < 300` using `* {cursor: none;}` - disable is not possible – Grijesh Chauhan Nov 16 '12 at 11:09
  • may be this can give you some idea http://stackoverflow.com/questions/219322/how-can-i-use-javascript-timing-to-control-on-mouse-stop-and-on-mouse-move-event. but javascript alone can't provide you this.You can either hide the cursor or give an alert or something by highlighting the maximum permissible area. – ankur Nov 16 '12 at 11:11
  • @Esailija: To prevent an illegal resizing action seems reasonable. – Michael Scheper Sep 19 '16 at 18:29

3 Answers3

10

The Pointer Lock API might be what you're looking for

https://developer.mozilla.org/en-US/docs/API/Pointer_Lock_API

Community
  • 1
  • 1
lostsource
  • 21,070
  • 8
  • 66
  • 88
5

Javascript can read mouse position but not set it. The mouse cursor properties exist outside the HTML Document Object Model and thus are beyond the reach of Javascript. Mouse events however are captured and thus readable / event modification also permissible (mouse hover, mouse over, mouse out, mouse click, dblclick).

Gadde
  • 1,451
  • 15
  • 37
2

You cannot do this with JavaScript and I dare say you never will be able to.

If you need to do this for some kind of game element, for example, I recommend that you place a page-element under the mouse and prevent the page-element from moving outside of the bounds even if the mouse does.

Fenton
  • 241,084
  • 71
  • 387
  • 401