移动鼠标光标Javascript [英] Move Mouse Cursor Javascript

查看:101
本文介绍了移动鼠标光标Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一家公司开发一个笑话微型网站。他们需要一个功能,当用户将鼠标悬停在特定图像上时,鼠标光标将随机更改位置。



这是可能的Javascript吗?我将如何实现它?



谢谢!

解决方案

但是,你可以 - 在某种程度上。

模仿这种行为你可以做的事情是你可以用css cursor:none 和然后创建一个表示光标的图像,该图像看起来相同并且将放置在真实光标的位置上。然后,当用户移动鼠标时,您必须更新光标图像的位置并随意应用您的随机位置更改 - 但请注意,当用户将在浏览器内容窗口之外滚动时(在控件上或外部浏览器),他们会将鼠标指针移回到真实位置,并且您的光标将停留在最后一个位置。



只有这样才能把这个恶作剧拉出来。祝你好运,并希望他们会喜欢它;)

PS。



反转鼠标移动方向也可以很有趣:>

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

inverting the mouse movement direction can be funny as well :>

这篇关于移动鼠标光标Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆