让用户在 div/img 上画一条线(箭头)
使用 jQuery 插件:imgareaselect (http://odyniec.net/projects/imgareaselect/),我让用户选择图像区域来添加评论(就像 flickr)。 我的目标是让用户绘制指向特定图像区域的箭头而不是绘制方框。
知道是否(以及如何)我可以修改 imgareaselect 来绘制线条(带有箭头)而不是选择框吗?
我读到我可以使用 Canvas 或processing.js,但据我所知,这些要么不起作用,要么在 IE 上有限制。
谢谢, 亚西尔
Using the jQuery plugin: imgareaselect (http://odyniec.net/projects/imgareaselect/), I let users select areas of an image to add comments (just like flickr).
I'm aiming to let users draw arrows pointing on specific image areas instead of drawing boxes.
Any idea if (and how) I can modify imgareaselect to draw lines (with an arrow head) instead of selection boxes?
I read that I could use Canvas or processing.js, but AFAIK those either don't work or have limitations on IE.
Thanks,
Yasser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 CSS 绝对定位将一组箭头图像叠加在照片顶部。例如,制作 18 个箭头,每个箭头都从最后一个箭头旋转 360° / 18 = 20°。使用 CSS sprite 技术应该可以改变箭头的长度。
在下面的描述中,我将箭头的开始称为文本框附近的结束位置,将结束称为图片上指向的点。
为了计算(顺时针)箭头角度以使用给定的一对像素指向的 xy 坐标和文本框位置的坐标,我们使用:
然后您的脚本可以选择最接近的预制箭头:
加载箭头时,根据以下条件定位其左上角(相对于末端):
其中 l 是箭头的长度。
最后,修剪箭头:
并将文本框的中心放在箭头的起点上。
You can make a set of arrow images to overlay, using CSS absolute positioning, on top of the photo. For example, make 18 arrows, each rotated from the last one by 360° / 18 = 20°. Using the CSS sprite technique should allow you to vary the length of the arrow.
In the description that follows, I refer to the start of the arrow as the end near the textbox, and the end as the spot that is pointed to on the picture.
To calculate the (clockwise) arrow angle to use given a pair of x-y coordinates of the pixel pointed to and those of the text box location, we use:
Then your script could choose the closest pre-made arrow:
When the arrow is loaded, position its top-left corner (relative to the end) according to:
where l is the length of the arrow.
Finally, trim the arrow:
and put the center of the text box on the start of the arrow.