Move an image according to the mouse cordinates using jquery

落花浮王杯 提交于 2019-12-22 09:36:01

问题


I am trying to develop a HTML5 white board. I want the users viewing the board to know where exactly the presenter is pointing within the screen. I am able to collect the mouse movements using this jquery function.

But even if i succeed to pass this values to other clients using php, how can I emulate it? Is it possible to move a small pointer image, based on the co-ordinates obtained from the presenter?

  1. Is there any functions or snippets from which I cant get started?
  2. Will this be very hardware intensive task that normal people may have issue?
  3. Is this the best way to achieve what I am trying to achieve?

回答1:


Well you can move the image using .css

such as:

$(window).mousemove(function(event) {
  $("#image").css({"left" : event.pageX, "top" : event.pageY});
});

just set #image to fixed or absolute

  1. above

  2. This is not very hardware intensive at all. As long as you use .css and not .animate

  3. This is probably the easiest and most robust solution




回答2:


This has actually been done with tutorial included with Node.js and websockets. (note, you may not actually see any other cursors as that post is quite old, but you may be able to see yourself by using another computer/browser).

You say you want to use PHP, and you can probably port his node.js code to php. Here is a library to help with websockets in php.




回答3:


Create an image on the page with the whiteboard on the viewers browser. Set the image style to position:absolute and from javascript set the top and left properties acording to the position from the presenters mouse. Use setInterval to make a javascript call to the server and obtain the presenters mouse position. At the presenters computer you need to use setInterval as well to save the mouse position on the server.



来源:https://stackoverflow.com/questions/6733570/move-an-image-according-to-the-mouse-cordinates-using-jquery

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