jQuery 设置鼠标位置(不是光标位置)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1208729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Set Mouse Position (not cursor position)
提问by Michael
I have a link that, when clicked, I would like it to move the position of the mouse to the right (or anywhere within the viewport, for that matter).
我有一个链接,单击该链接时,我希望将鼠标的位置向右移动(或视口内的任何位置,就此而言)。
in code it would probably look similar to the following:
在代码中,它可能类似于以下内容:
$('a#expand').click(function(e){
$(document)
.mouseXPos(e.pageX + 50)
.mouseYPos(e.pageY + 50);
});
Chaining might not be necessary, of course, but a similar 'set mouse position' functionality is what I am after.
当然,链接可能不是必需的,但类似的“设置鼠标位置”功能正是我所追求的。
I've seen solutions to move the cursor position to a certain spot in the text, but I didn't glean much from them.
我已经看到将光标位置移动到文本中某个位置的解决方案,但我并没有从它们中收集到太多信息。
回答by MyItchyChin
There is no mechanism for moving the mouse via JavaScript.
没有通过 JavaScript 移动鼠标的机制。
回答by Jason Musgrove
I may be wrong, but I don't think it's possible to move the mouse pointer from client-side script. Given the potential for abuse, I certainly hope it isn't.
我可能错了,但我认为不可能从客户端脚本移动鼠标指针。鉴于滥用的可能性,我当然希望不是。
回答by George
There's no way to accomplish mouse position change via JavaScript or any Client-Side Script. The only reason for that is not to give a client side script potential for abuse as stated before.
无法通过 JavaScript 或任何客户端脚本完成鼠标位置更改。这样做的唯一原因是不要像之前所说的那样给客户端脚本提供滥用的可能性。
回答by Zuul
You could hide the cursor, and show another one at a different place.
您可以隐藏光标,并在不同位置显示另一个光标。
Good to have when moving around in a maze for example. The cursor looks like it's stopped but you will see it again when you move outside the window.
例如,在迷宫中四处走动时很高兴。光标看起来像是停止了,但是当您移到窗口外时,您会再次看到它。
回答by Mahsa Teimourikia
As other users already have mentioned, there isn't any mechanism is Javascript to do that. However, you can disable the mouse and implement a cursor to do what you need. Here is a link that explains how. How to implement a custom cursor.
正如其他用户已经提到的那样,Javascript 没有任何机制可以做到这一点。但是,您可以禁用鼠标并实现光标来执行您需要的操作。这是一个解释如何操作的链接。如何实现自定义光标。
回答by Wajahat Ali
You map change scroll position that will automatically move your pointer to required position;
您映射更改滚动位置,它将自动将您的指针移动到所需位置;
$(document).scrollTop();
For some case, I was required to stay pointer on same checkbox although a button show/hide was causing a bubbling... so I did something like;
在某些情况下,尽管按钮显示/隐藏导致冒泡,但我需要将指针停留在同一个复选框上……所以我做了类似的事情;
$(document).scrollTop( $(document).scrollTop() + parseInt($('.btn-show-selected-group').outerHeight()) );
$(document).scrollTop( $(document).scrollTop() - parseInt($('.btn-show-selected-group').outerHeight()) );