简体   繁体   English

移动鼠标光标Javascript

[英]Move Mouse Cursor Javascript

I'm building a joke microsite for a company. 我正在为一家公司开一个玩笑的微型网站。 They want a feature where the mouse cursor will randomly change position when the user hovers over a certain image. 他们需要一种功能,当用户将鼠标悬停在某个图像上时,鼠标光标将随机更改位置。

Is this possible in Javascript? 这可能在Javascript中吗? How would I implement it? 我将如何实施?

Thanks! 谢谢!

You can't... but you can - in a way. 您不能...但是可以-在某种程度上。

What you can do to mimic this behavior is that you can hide the actual cursor with css cursor: none and then create an image representing the cursor which would look the same and would be placed in position of the real cursor. 可以模仿此行为的方法是,可以使用css cursor: none隐藏实际的光标cursor: none ,然后创建一个表示该光标的图像,该图像看起来相同并将放置在实际光标的位置。 Then whe user would move the mouse you'd have to update the position of the cursor image and apply your random position changes as you wish - though be aware that when user will scroll outside of the browser content window (on the controls or outside the browser) they will get their mouse cursor back to real position and your cursor will be stuck in its last position. 然后,用户需要移动鼠标来更新光标图像的位置,并根据需要应用随机位置更改-尽管请注意,用户何时滚动到浏览器内容窗口之外(控件上还是控件外)浏览器),它们会将鼠标光标恢复到实际位置,并且光​​标将停留在其最后一个位置。

The only way you could pull this prank out. 您唯一可以拉出这个恶作剧的方法。 Good luck with it and hope they'll enjoy it ;) 祝你好运,希望他们会喜欢;)

PS. PS。

inverting the mouse movement direction can be funny as well :> 反转鼠标的移动方向也可能很有趣:

You can't move the mouse cursor. 您无法移动鼠标光标。

You can move the page or the image relative to the position of the cursor, which might make it look like the cursor moved when it didn't? 您可以相对于光标的位置移动页面或图像,这可能会使它看起来像是光标在未移动时移动了吗?

您可以使用不可见的自定义图标更改光标,然后制作一个假光标并将其移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM