html5之SVG

html之SVG


  • whit’s is the SVG?
    • SVG stands for Scalable Vector Graphics
    • SVG is used to define graphics for the web
    • SVG is a W3C recommedation

  • The HTML < svg > Element
    • The HTML < svg > element is a container for SVG graphics.
    • SVG has several methods for drawing paths, boxes, circles, text, and graphics images.

  • Browser Support:
    The numbers in the table specify the first browser version that fully supports the < svg > element.
     SVG Browser Support

  • SVG Circle
    SVG Circle
  • Example
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Svg Circle</title>
    </head>
    <body>
        <svg width="100" height="100">
            <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
        </svg>
    </body>
</html>
  • SVG Rectangle
    SVG Rectangle
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>SVG Rectangle</title>
    </head>
    <body>
        <svg width="400" height="100">
            <rect width="400" height="100" style="fill:rgb(0,0,255); stroke-width:10; stroke:rgb(0,0,0)" />
        </svg>
    </body>
</html>
  • SVG Rounded Rectangle
    SVG Rounded Rectangle
 <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>SVG Rounded Rectangle</title>
    </head>
    <body>
        <svg width="400" height="180">
            <rect x="50" y="20" rx="20" ry="20" width="150" height="150" style="fill:red; stroke:black; stroke-width:5 opacity:0.5" />
        </svg>
    </body>
</html>
  • SVG Star
     SVG Star
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>SVG Star</title>
    </head>
    <body>
        <svg width="300" height="200">
  <polygon points="100,10 40,198 190,78 10,78 160,198"
  style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" >
</svg>
    </body>
</html>
  • SVG Logo
    SVG Logo
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>SVG Star</title>
    </head>
    <body>
    <svg height="130" width="500">
   <defs>
    <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
      <stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
      <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
    </linearGradient>
   </defs>
  <ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#grad1)" />
  <text fill="#ffffff" font-size="45" font-family="Verdana" x="50" y="86">SVG</text>
  Sorry, your browser does not support inline SVG.
</svg>

    </body>
</html>

  • Differences Between SVG and Canvas
    • SVG is language for describing 2D graphics in XML.
    • Canvas draws 2D graphics, on the fly (with a JavaScript).
    • SVG is XML based, which means that every elements is available within the SVG DOM.You can attach JavaScript event handles for an element.
    • In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.
    • Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic.

  • Comparison of Canvas and SVG
    • The table below shows some important differences between Canvas and SVG:
      Comparison of Canvas and SVG

W3C-SVG
JackDan9 Thinking.


Thank you for reading my article.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值