SVG在HTML5中的应用

SVG(Scalable Vector Graphics)是用来绘制矢量图的HTML5标签。只要定义好XML属性就能够获得与其一致的图像元素。

 使用SVG之前先将标签加入到HTML body中。就像其他的HTML标签一样,你可以为SVG标签为之添加ID属性。也可以为之添加css样式,例如“border-style:solid;border-width:2px;”。SVG标签跟其它的HTML标签有通用的属性。你可以用height="100px" width="200px" 为其添加高度和宽度。

一、      用SVG画线条:

<svg >

     <line x1="10" y1="20" x2="100" y2="200" style="stroke:Green;stroke-width:2"/>

</svg>

其中:指定x1,y1,x2,y2值来代表起点终点坐标,在style属性中使用“stroke:Green;”为线条指定颜色。用stroke-width:2为线条设置宽度。

 关于HTML5用SVG画图

二、      用SVG画圆:

<svg >

 <circle />

</svg>

其中:圆的中心cx="55" cy="55",半径r="50",fill="#219E3E"填充颜色,stroke="#17301D" stroke-width="2"线条颜色与宽度

 关于HTML5用SVG画图

三、      用SVG画矩形

<svg >

    <rect />        

</svg>

其中:stroke="#17301D" stroke-width="2"定义边框的颜色和宽度

 关于HTML5用SVG画图

四、      SVG画椭圆

<svg >
    <ellipse cy="60" rx="100" ry="50" style="fill:#3F5208;stroke:black;stroke-width:3"/>   
</svg>

其中:中心坐标cx="120" cy="60",长轴短轴半径 rx="100" ry="50"

 关于HTML5用SVG画图

五、      SVG画多边形

<svg xmlns="http://www.w3.org/2000/svg">

    <polygon 10,10 75,150 150,60" style="fill:blue;stroke:black;stroke-width:3"/>

</svg>

points="10,10 75,150 150,60"定义三个顶点(10,10),(75,150),(150,60)

 关于HTML5用SVG画图

举例:

<!DOCTYPE html>

<html>

<body>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">

  <polygon points="100,10 40,180 190,60 10,60 160,180"

  style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;">

</svg>

</body>

</html>

 关于HTML5用SVG画图

相关文章:

  • 2021-11-17
  • 2021-06-09
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案