拉斐尔 - 用鼠标绘制形状
使用鼠标绘制矩形或圆形的最佳方法是什么?
我刚开始看拉斐尔,看来我应该使用,拖动?或者 mousedown 和 mouseup ?
不确定。
What would be the best way to draw a rectangle or circle for that matter using your mouse ?
I just started looking at raphael and it seems I should use, drag? Or mousedown and mouseup ?
No sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会在画布/纸张上使用 mousedown 和 mouseup 事件。在鼠标按下时,您应该存储鼠标按下时的 x 和 y 位置,然后在鼠标按下时,您应该使用当前鼠标位置来计算宽度和高度。
这是一个示例,请记住,我正在使用 JQuery 来计算鼠标位置(如果这不适用于你,那么你应该找到另一种方法来获取鼠标偏移)
希望有帮助
I would use mousedown and mouseup events on your canvas/paper. On mouse down you should store the x and y positions of the mousedown, then on mouseup you should use the current mouse positions to calculate width and height.
Here is an example, bear in mind thought that I am using JQuery to calculate the mouse positions (if this is not available for you, then you should find another way to get the mouse offsets)
Hope that helps
这是 fiddle 的更新版本(在其他文章)适用于 Raphael 2+(无纸质事件)。
这个小提琴展示了拖动鼠标时如何动态绘制矩形。
Here's an updated version of fiddle (mentioned in the other article) that works with Raphael 2+ (no paper events).
This fiddle shows how a rectangle is dynamically drawn while you drag the mouse.
我尝试修改米罗的上述小提琴。请在此处查看我的更新版本
这里也是与 Raphael Js 一起玩的一个很好的参考。
http://www.ebooksbucket.com/instant-raphaeljs-starter-b184
希望这会有所帮助。
I have tried to modify the above fiddle from Miro. Please check my updated version here
Here is also a good reference to play with Raphael Js.
http://www.ebooksbucket.com/instant-raphaeljs-starter-b184
Hope this will help.