Move Mouse Cursor Javascript

十年热恋 提交于 2019-12-17 16:28:43

问题


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!


回答1:


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 :>




回答2:


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?




回答3:


You can change your cursor with invisible custom icon, and then make a fake cursor and move it.



来源:https://stackoverflow.com/questions/4804068/move-mouse-cursor-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!