最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript - How to stop mouse movement - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Nov 16, 2012 at 11:06 ShlomoShlomo 3,9908 gold badges52 silver badges82 bronze badges 5
  • Of course not, why would you want to do this? – Esailija Commented Nov 16, 2012 at 11:08
  • 2 I love javascript, but I really hope it will not ever be able to control my mouse. – Amberlamps Commented Nov 16, 2012 at 11:08
  • You can hide cursor after left < 300 using * {cursor: none;} - disable is not possible – Grijesh Chauhan Commented Nov 16, 2012 at 11:09
  • may be this can give you some idea stackoverflow.com/questions/219322/…. 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 Commented Nov 16, 2012 at 11:11
  • @Esailija: To prevent an illegal resizing action seems reasonable. – Michael Scheper Commented Sep 19, 2016 at 18:29
Add a comment  | 

3 Answers 3

Reset to default 11

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

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

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).

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.

发布评论

评论列表(0)

  1. 暂无评论