使用jquery根据鼠标坐标移动图像

发布于 11-25 02:54 字数 342 浏览 6 评论 0原文

我正在尝试开发一个 HTML5 白板。我希望用户查看该图板 了解演示者具体指向屏幕内的哪个位置。我能够 使用 这个 jquery 函数收集鼠标移动。

但即使我成功传递了这个值 对于其他使用 php 的客户端,我该如何模拟它? 是否可以移动一个小 指针图像,基于从演示者获得的坐标?

  1. 是否有任何我无法开始的函数或片段?
  2. 这是否是普通人可能会遇到的硬件密集型任务? 有问题吗?
  3. 这是实现我想要实现的目标的最佳方式吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海夜未眠2024-12-02 02:54:46

那么您可以使用 .css 移动图像,

例如:

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

只需将 #image 设置为固定或绝对

  1. above

  2. 这不是很硬件密集型。只要您使用 .css 而不是 .animate

  3. 这可能是最简单、最强大的解决方案

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

花间憩2024-12-02 02:54:46

这实际上已经通过 Node.js 和 websockets 附带的教程完成了。 (请注意,您实际上可能看不到任何其他光标,因为该帖子已经很旧了,但您可能可以通过使用另一台计算机/浏览器看到自己)。

你说你想用PHP,你大概可以把他的node.js代码移植到php。这是一个帮助php 中的 websocket 的库。

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.

小苏打饼2024-12-02 02:54:46

在查看者浏览器上使用白板在页面上创建图像。将图像样式设置为position:absolute,并从javascript 根据演示者鼠标的位置设置顶部和左侧属性。使用 setInterval 对服务器进行 javascript 调用并获取演示者鼠标位置。在演示者计算机上,您还需要使用 setInterval 来保存服务器上的鼠标位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文