svg:可以不改變質量的情況下縮放
- svg必須有<svg></svg>包含
- 可以繪制不同的形狀矩形:rect,圓形:circle,橢圓:ellipse,線:line,折線:polyline,多邊形:polygon,路徑:path
- 繪制不同的圖形則應該使用不同的標簽標記如圓形則使用<svg>circle</svg>
- 可以將svg保存為svg格式
- x,y表示起始坐標
- fill:填充的顏色,stroke:畫的顏色,stroke-width:畫的寬度(通俗來講就是邊框)
- 其實和css3的canvas差不多
矩形:rect
<svg> <rect fill="red" height="100" id="rect" stroke="gray" stroke-width="10" width="100" x="20" y="20"></rect> </svg>
圓角矩形:設置rx,ry(圓心的坐標)的值即可
<svg> <circle id="circle"cx="100" cy="80" r="50" stroke="gray" stroke-width="10" fill="red"> </svg>
圓形:circle
circle:沒有x,y的屬性因為已經設置好了圓心cx,cy
<svg class="grid-50"> <rect fill="red" height="100" id="rect" stroke="gray" stroke-width="10" width="100" x="20" y="20"></rect> </svg>
橢圓:ellipse
ellipse:橢圓其實就是矩形然后邊框是圓角
<svg > <ellipse rx=100 ry=30 cx=150 cy=60 fill="yellow" stroke="gray" /> </svg>
線段:line(兩點確定一條直線)
<svg> <line x1="0" y1="0" x2="200" y2="20" fill="gray" stroke="gray" stroke-width="2" /> </svg>
折線:polyline(就是設置多個坐標點)
注意不能使用(0,0)是無效的
<svg> <polyline points="0,0 0,20 20,20 20,40 40,40" fill="white" stroke="gray" stroke-width="2" /> </svg>
多邊形:polygon
當然更復雜的圖形,只要知道各個點的坐標即可
<svg > <polygon points="50,50 0,100 100,100 50,50" fill="blue" stroke="gray" stroke-width="1"> </svg>
路徑:path(上面所有的圖形 都可以通過path來繪制)
下面的命令可用於路徑數據:
- M = moveto //坐標移動到
- L = lineto //畫到
- H = horizontal lineto
- V = vertical lineto
- C = curveto
- S = smooth curveto
- Q = quadratic Belzier curve
- T = smooth quadratic Belzier curveto
- A = elliptical Arc //橢圓
- Z = closepath //結束路徑
注釋:以上所有命令均允許小寫字母。大寫表示絕對定位,小寫表示相對定位。
必須按照規則書寫
<svg> <path d="M50 50 L200 50 L200 0 L50 0 Z" fill="blue" stroke="gray" stroke-width="2" /> </svg>
原文地址url:
http://liteng.org/node/51