前端

HTML5之SVG的使用

2019-03-18  本文已影响16人  暖A暖

一、什么是SVG?

二、SVG的优势

三、使用SVG绘制圆形

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" height="500px" width="500px" version="1.1">
      <circle cx="200" cy="100" r="100" stroke="#afeedd"
      stroke-width="5" fill="#f0ddff" />
    </svg>
</body>
</html>

四、使用SVG绘制矩形

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" width="500px" height="500px" version="1.1">
      <rect x="50" y="100" width="300" height="150"
      style="fill:rgb(145,245,255);stroke-width:5;stroke:#EE799F;fill-opacity:0.9;stroke-opacity:0.9;"/>
    </svg>
</body>
</html>

五、使用SVG绘制多边形

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px">
      <polygon points="100,10 40,180 190,60 10,60 160,180" style="fill:#B4EEB4;stroke:#DB7093   ;stroke-width:3;fill-rule:nonzero;"/>
    </svg>
</body>
</html>

六、SVG模糊效果

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <defs>
            <filter id="keai" x="0" y="0">
                <feGaussianBlur in="SourceGraphic" stdDeviation="10" />
            </filter>
        </defs>
    <rect width="150" height="100" stroke="red" stroke-width="5"
  fill="#7EC0EE" filter="url(#keai)" />
    </svg>
</body>
</html>

七、SVG 阴影

<body>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px">
      <defs>
        <filter id="myImg" x="0" y="0" width="200%" height="200%">
          <feOffset result="offOut" in="SourceGraphic" dx="10" dy="10" />
          <feColorMatrix result = "matrixOut" in = "offOut" type = "matrix" values = "0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0"/>
          <feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="10" />
          <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
        </filter>
      </defs>
      <rect width="200" height="200" stroke="#90EE90" stroke-width="5" fill="#FFEFDB" filter="url(#myImg)" />
    </svg>
</body>

八、SVG渐变

<body>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="500px">
        <defs>
            <linearGradient id="yuan" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" style="stop-color:rgb(238,210,238);stop-opacity:1" />
            <stop offset="100%" style="stop-color:rgb(255,250,205);stop-opacity:1" />
            </linearGradient>
        </defs>
        <ellipse cx="200" cy="200" rx="150" ry="80" fill="url(#yuan)" />
    </svg>
</body>
上一篇下一篇

猜你喜欢

热点阅读