SVG自整理,SVG整理

來源:互聯網
上載者:User

SVG自整理,SVG整理
1.什麼是SVG?

SVG 指可伸縮向量圖形 (Scalable Vector Graphics)

SVG 用來定義用於網路的基於向量的圖形

SVG 使用 XML 格式定義圖形

SVG 映像在放大或改變尺寸的情況下其圖形品質不會有所損失

2.簡單的 SVG 執行個體

一個簡單的SVG圖形例子:

這裡是SVG檔案(SVG檔案的儲存與SVG擴充):

<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /></svg>

SVG 代碼解析:

  • 第一行包含了 XML 聲明。請注意 standalone 屬性!該屬性規定此 SVG 檔案是否是"獨立的",或含有對外部檔案的引用。standalone="no" 意味著 SVG 文檔會引用一個外部檔案 - 在這裡,是 DTD 檔案。
  • 第二和第三行引用了這個外部的 SVG DTD。該 DTD 位於 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"。該 DTD 位於 W3C,含有所有允許的 SVG 元素。
  • width 和 height 屬性可設定此 SVG 文檔的寬度和高度。version 屬性可定義所使用的 SVG 版本,xmlns 屬性可定義 SVG 命名空間。
  • SVG 的 <circle> 用來建立一個圓。cx 和 cy 屬性定義圓中心的 x 和 y 座標。如果忽略這兩個屬性,那麼圓點會被設定為 (0, 0)。r 屬性定義圓的半徑。
  • stroke 和 stroke-width 屬性控制如何顯示形狀的輪廓。我們把圓的輪廓設定為 2px 寬,黑邊框。
  • fill 屬性設定形狀內的顏色。我們把填充顏色設定為紅色。
3.SVG 矩形 - <rect>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1; stroke-opacity:0.9"/></svg>
4.SVG 圓形 - <circle>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/></svg>
5.SVG 橢圓 - <ellipse>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <ellipse cx="300" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2"/></svg>
6.SVG 直線 - <line>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">

    //x1 屬性在 x 軸定義線條的開始

    //y1 屬性在 y 軸定義線條的開始

    //x2 屬性在 x 軸定義線條的結束

    //y2 屬性在 y 軸定義線條的結束

    <line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2"/>

  </svg>

7.SVG 路徑 - <path>

<path> 元素用於定義一個路徑。

下面的命令可用於路徑資料:

  • M = moveto
  • L = lineto
  • H = horizontal lineto
  • V = vertical lineto
  • C = curveto
  • S = smooth curveto
  • Q = quadratic Bézier curve
  • T = smooth quadratic Bézier curveto
  • A = elliptical Arc
  • Z = closepath
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <path d="M150 0 L75 200 L225 200 Z" /></svg>

命令詳細用法請參見:https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths

svg動畫請參考:http://www.zhangxinxu.com/wordpress/2014/08/so-powerful-svg-smil-animation/

8.SVG 文本 - <text>

<!-- 普通文本 -->

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <text x="0" y="15" fill="red">I love SVG</text></svg>

<!-- 轉動文本 -->

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <text x="0" y="15" fill="red" transform="rotate(30 20,40)">I love SVG</text></svg>

<!-- 連結文本 -->

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">  <a xlink:href="http://www.w3schools.com/svg/" target="_blank">     <text x="0" y="15" fill="red">I love SVG</text>  </a></svg>

 //其他用法後序補上

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.