画个矢量图——HTML5-SVG
应用场景
SVG 的优势
开始
<!-- 定义绘图区域 -->
<svg width="500px" height="500px"></svg>代码示例
<svg width="500px" height="500px">
<!-- 直线 -->
<!-- x1, y1 x2, y2 定义两点坐标 -->
<line x1="100" y1="100" x2="200" y2="100"></line>
<!-- 矩形 -->
<!-- x , y 是起始坐标,width 和 height 是自解释的。rx, ry是定义圆角 -->
<rect x="50" y="50" width="100" height="100" rx="10" ry="20"></rect>
<!-- 圆形 -->
<!-- 半径 圆心 -->
<circle r="50" cx="220" cy="100"></circle>
<!-- 椭圆形 -->
<!-- x轴,y轴 圆心 -->
<ellipse rx="100" ry="50" cx="100" cy="200"></ellipse>
<!-- 折线 -->
<!-- 使用 points 定义多个点 各组点使用逗号分开 -->
<polyline
points="60 50, 75 35, 100 50, 125 35, 150 50, 175 35, 190 50"
></polyline>
<!-- 多边形 -->
<!-- 通过定义多个点 进行连线 -->
<polygon points="125 125, 130 140, 120 140"></polygon>
<!-- 文本 -->
<text x="125" y="220">Hello Lambda</text>
</svg>
/* 使用 css 定义svg样式 */
svg {
/* 线条颜色 */
stroke: #000;
/* 线条粗细 */
stroke-width: 5;
/* 线条样式 */
stroke-linecap: round;
stroke-linejoin: round;
/* 填充 */
fill: #f40;
/* 线条透明度 */
stroke-opacity: 0.8;
/* 填充透明度 */
fill-opacity: 0.6;
}
path 元素
代码示例





线性渐变

径向渐变

高斯模糊滤镜

SVG 路径动画
代码示例

JS 生成 SVG 元素

canvas 和 svg 区别
最后更新于