如何用GWT或HTML+CSS+JavaScript绘制对角线?
我正在开发一个网络应用程序,我需要用线连接东西。如果线条不限于水平/垂直,那就太好了。我还需要检测线路上的点击。到目前为止我考虑的替代方案:
使用 CSS 旋转
我创建一个具有适当长度的 div 或 hr,然后在其样式中使用 CSS 变换属性。在这个网站的某个地方有一个关于它的答案。
优点:
- 简单。
- 可以检测点击。
缺点:
- 需要浏览器特定的 CSS。
在服务器上创建图像
我创建了一个网页,它将 fromx、fromy、tox、toy 作为 GET 或 POST 参数,并返回该行的图像。
优点:
- 简单。
- 标准。
缺点:
- 如果线交叉,我无法检测到点击。 (确实如此。)
- 需要服务器参与。
使用多个小 div
我创建了大量 5x5 div 并将它们放置成一条线。
优点:
- 可以检测点击。
- 标准。
缺点:
- 疯狂。
放弃
我放弃并使用 gwt-connectors。它只绘制水平线和垂直线,但至少它非常简单并且连接的对象可以移动。
您推荐哪个选项?还有其他我没有考虑过的吗?
I am working on a web application where I need to connect stuff with lines. It would be nice if the lines would not be restricted to horizontal/vertical. I also need to detect clicks on the lines. The alternatives I considered so far:
Use the CSS rotate
I create a div or hr with the proper length then I use the CSS transform attribute in their style. There is an answer about it somewhere on this site.
Advantages:
- Simple.
- Can detect clicks.
Disadvantages:
- Requires browser specific CSS.
Creating the image on the server
I create a webpage which takes fromx, fromy, tox, toy as GET or POST parameters and gives back the image of the line.
Advantages:
- Simple.
- Standard.
Disadvantages:
- I can not detect clicks if the lines are crossed. (Which they are.)
- Requires server involvment.
Use multiple small divs
I create tons of 5x5 divs and position them to form a line.
Advantages:
- Can detect clicks.
- Standard.
Disadvantages:
- Crazy.
Give up
I give up and use gwt-connectors. It only draws horizontal and vertical lines but at least it is very simple and the connected objects can be moved.
Which option do you recommend? Any other I have not considered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有 CSS3 可用: http://jsfiddle.net/rudiedirkx/MKkxX/
连接点,这将需要大量(非常小,非常简单)的计算。服务器端计算。每条线的旋转和平移以及线长度都不同。这是很多计算。但这对客户来说非常简单。如果客户端支持 CSS3 =)
If you have CSS3 available: http://jsfiddle.net/rudiedirkx/MKkxX/
Connecting dots, this will require a lot of (very small, very simple) calculations. Server side calculations. The rotations and translations and line lenghts will be different for each line. That's a lot of calculations. But it'll be very simple for the client to do. That's if the client has CSS3 support =)
我会选择: http://raphaeljs.com/ 这是一个跨平台的 javascript 库,用于创建和渲染 SVG
I would go with: http://raphaeljs.com/ which is a cross platform javascript library that creates and renders SVG
您可以添加画布元素并通过脚本(例如 jQuery)绘制一条线。 Canvas 从 IE9 开始受支持并使用 IECanvas polyfil。
我循环遍历每个具有 .class“线框”的元素,并在其中添加一个画布元素。我使用与边框相同的颜色,以便画布保持正确的样式。
});
You can add a canvas element and draw a line through script (eg jQuery). Canvas is supported from IE9 and using the IECanvas polyfil.
I loop through each element that has the .class 'wireframe' and add a canvas element inside it. I use the same color as the border so that the canvas maintains the correct style.
});