关注开源代码的实际应用
Raphaël 是一个小巧的JavaScript图形库,通过它可以在网页中类似于Windows的GDI方式进行绘图。Raphaël底层通过SVG或VML实现,支持的浏览器有Firefox 3.0+, Safari 3.0+, Opera 9.5+ 和Internet Explorer 6.0+。Raphaël基于MIT License发布。
在页面中引用raphael.js脚本文件后,就可以像下面这样进行绘图了:
- // Creates canvas 320 × 200 at 10, 50
- var paper = Raphael(10, 50, 320, 200);
- // Creates circle at x = 50, y = 40, with radius 10
- var circle = paper.circle(50, 40, 10);
- // Sets the fill attribute of the circle to red (#f00)
- circle.attr("fill", "#f00");
- // Sets the stroke attribute of the circle to white (#fff)
- circle.attr("stroke", "#fff");
演示: